This is the mail archive of the 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]

Re: malloc() problem

On Thu, Feb 06, 2003 at 05:35:01PM -0500, Greg Smith wrote:
>>>There's also a bug right now that causes allocation of three times as
>>>much memory as Hercules actually calls for.  (I believe that one's
>>>already been reported; it really hits Hercules hard, though, as it's
>>>not uncommon to have Hercules allocate 256 MB of memory for the
>>>emulated system's central storage, and a 768 MB allocation will drive
>>>most Windows boxes to their knees.)
>>I'm not aware of any bug report along these lines.  I must have missed
>>A test case would be welcome.
>One of our developers has come up with a test case for this problem
>which I have pasted below.  He's basically a windows programmer and
>I don't think he can write a short program to save his life ;-)

A test case is not a 218 line program.  Sorry.

I did write a very small test case which malloced 4M and saw the problem
you described by watching memory size go up in task manager.  The
problem seems to be due to the fact that the new version of malloc uses
mmap for requests over 256K and mmap is, for some reason, doubly
allocating private regions.

I've set the threshold up to a larger number in malloc and built a
new snapshot.  This should work around the problem until we can figure
out what is going wrong with mmap.  I've alerted our mmap maintainer
to the problem.

So, try the snapshot and see if it fixes your problem.

For your edification, the below is what I mean by a "test case".  A
"test case" should be source code which demonstrates the problem in
the smallest amount of code possible.  The below has an extra bell
or whistle but it at least should be understandable without a lot
of study.


#include <stdlib.h>
#include <unistd.h>

main(int argc, char **argv)
  char *p;
  unsigned size = strtoul (*++argv ?: "4194304", &p, 0);
  int i;
  printf ("pid %d\n", getpid());
  for (i = 0; i < 1000; i++)
      char buf[16];
      malloc (size);
      puts ("ding");
      gets (buf);
Please use the resources at rather than sending personal email.
Special for spam email harvesters: send email to
and be permanently blocked from mailing lists at

Unsubscribe info:
Bug reporting:

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