This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

malloc-bzero and /proc/pid/statm reading bug


on the ngspice development list one of the developer
find a likely cygwin bug, see description an test case

--- Dom 12/9/10, Robert Larice  ha scritto:

> Hello All,
> 
> ? I need some help with a cygwin Problem.
> ? Trying to find a bug reported for ngspice,
> ? ? I finally could boil the problem down
> ? ? to what seems to be a plain cygwin bug.
> 
> ? The attached very small C file, fails
> ? ? after some iterations to open a
> ? ? certain /proc/.. entry
> 
[cut]
> 
> ? Here I get:
> ? ???malloc -> 0x7fd30008
> ? ???malloc -> 0x7fab0008
> ? ???malloc -> 0x7f830008
> ? ???malloc -> 0x7f470008
> ? ???malloc -> 0x7f1f0008
> ? ???malloc -> 0x7ef70008
> ? ???/proc/3044/statm: No error
> ? ???malloc -> 0x7ecf0008
> ? ???/proc/3044/statm: No error
> ? ???...
> 
> ? { No error, nevertheless means,
> ? ???the thing can't be read ... }
> 
> Thanks,
> ? Robert Larice

I checked and both 1.7.7 and the latest 20100912
show the issue.
Are we assuming something wrong and missing something else 
or is it a bzero bug ?

Marco



      
// (compile "make CFLAGS='-Wall -O2' t3 && ./t3.exe")
// (man "proc(5)")

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

static void
foo(const char *path)
{
  int length = 320000*8;
  void *blob = malloc(length);

  fprintf(stderr,"malloc -> %p\n", blob);

  /* writing to the alloced space causes failure to open /proc/$pid/statm */
  if(1)
    bzero(blob, length);

  {
    int hndl = open(path, O_RDONLY);
    if(hndl < 0)
      perror(path);
    else
      close(hndl);
  }
}


int
main(int argc, char **argv)
{
  char proc_statm[100];
  int i;

#if 0
  // just some info, for debugging purpose
  sprintf(proc_statm, "cat /proc/%d/maps | sort", getpid());
  system(proc_statm);

  // stat doesn't fail
  sprintf(proc_statm, "/proc/%d/stat", getpid());
#endif

  // statm will fail
  sprintf(proc_statm, "/proc/%d/statm", getpid());

  for(i=0; i<60; i++)
    foo(proc_statm);

  exit(0);
}

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]