www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/08/20/02:09:27

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_43,J_CHICKENPOX_53,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <c8a3efee0908190804i4130ecbfp7561934ab2272da8@mail.gmail.com>
References: <c8a3efee0908190447l11062bf1waba8ca9df5581468 AT mail DOT gmail DOT com> <20090819140322 DOT GB8713 AT ednor DOT casa DOT cgf DOT cx> <c8a3efee0908190804i4130ecbfp7561934ab2272da8 AT mail DOT gmail DOT com>
Date: Thu, 20 Aug 2009 14:09:10 +0800
Message-ID: <c8a3efee0908192309k4e207b4fs662d2c2baae8c0a2@mail.gmail.com>
Subject: Re: find(1) memory leak in cygheap
From: Haojun Bao <baohaojun AT gmail DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Wed, Aug 19, 2009 at 11:04 PM, Haojun Bao<baohaojun AT gmail DOT com> wrote:
> On Wed, Aug 19, 2009 at 10:03 PM, Christopher
> Faylor<cgf-use-the-mailinglist-please AT cygwin DOT com> wrote:
>> On Wed, Aug 19, 2009 at 07:47:37PM +0800, Haojun Bao wrote:
>>>I found this problem when running updatedb, the find will print
>>>
>>> =A0 =A0 =A02 [main] find 2592 C:\cygwin\bin\find.exe: *** fatal error -
>>>cmalloc would have returned NULL
>>>
>>>I have dumped the cygheap using gdb to see what's in it, the size is
>>>about 25M, and I use strings.exe to examine the strings
>>>in it, all the folder names that find has looked into is in it, both
>>>native format and cygwin format of the folders names.
>>>
>>>And there are lot's of folders in my android source folder, so the
>>>cygheap is filled up. I think maybe this is a memory leak?
>>>
>>>Please use the following script to test:
>>
>> How about if you provide us with cygcheck output first?
>>
> Sorry, here's the cygcheck output attached
>
I have done some debugging, and the culprit should be dup(2) syscall.
Here's another test case, this time written in C.

Note that the cygheap_start and cygheap_max value will be very likely
different on your computer, so you should use gdb to take a peek into
cygwin1.dll to get your value. Or else you should remove the reference
to these memory location.

The test case will show cygheap is always growing, and at the end it will p=
rint
  1 [main] a 3560 Q:\a.exe: *** fatal error - cmalloc would have returned N=
ULL

Here's the code:

#include <unistd.h>
     #include <sys/types.h>
     #include <dirent.h>
     #include <sys/types.h>
     #include <sys/stat.h>
     #include <fcntl.h>

void ** _cygheap_start =3D (void **)0x612076b0;
void ** cygheap_max =3D (void **)0x6114b104;

#include <stdio.h>

int main()
{
/*make a big buffer to fill quicker*/
	char buf[4095] =3D {'/'};
	int i;
	for (i=3D1; i<sizeof(buf)-1; i++) {
		buf[i]=3D'x';
		if (i%200 =3D=3D 0) {
			buf[i] =3D '/';
			if (mkdir(buf, 0777)<0) {
				printf("Error: mkdir %s", buf);
				exit(-1);
			}
		}
	}
	mkdir(buf, 0777);
	int fd =3D open(buf, O_RDONLY);
	while (1) {
		int fd2 =3D dup(fd);
		printf("fd2 is %d\n", fd2);
		close(fd2);
		printf ("heap start: 0x%08x, end: 0x%08x\n", *_cygheap_start, *cygheap_ma=
x);
	}
}

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019