Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Thu, 21 Aug 2003 18:49:44 +0100 From: Ljubomir Josifovski To: cygwin AT cygwin DOT com Subject: Re: 1.3.22-1 on XP: malloc returns overlapping buffers Message-ID: <20030821174944.GA25516@berk.cre.canon.co.uk> References: <20030820200711 DOT GA3964 AT delwin> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030820200711.GA3964@delwin> On Wed, Aug 20, 2003 at 04:07:11PM -0400, roconnor wrote: > I am finding that under some circumstances a buffer returned by malloc > will overlap with a buffer returned by a previous call to malloc that > has not been freed. I was able to reduce it to the following test > case. Running under cygwin 1.3.22-1 on Windows XP Professional > Version 2002 SP1 it reports an overlap of 4824 bytes on two different > machines, as well as on a third machine running Windows 2000 5.00.2195 > SP4. On Windows NT 4.0.1381, it finds no overlap. > > Am I doing something wrong or is there a bug in malloc or XP? More > details below. > > ------------------------------------------------------------------------ > > #include > #include > > int > main (int argc, char **argv) > { > char *mm = 0, *p; > int size = 8000, overlap; > > p = malloc (1); > > while (mm < p) { > mm = malloc (16777216); > if (mm == 0) { > printf ("not enough memory to run test\n"); > exit (0); > } > printf ("malloc (16777216) = %d\n", (int)mm); > } > > while ((p = malloc (size))) { > overlap = (int)p + size - (int)mm; > if (p < mm && overlap > 0) { > printf ("overlap = %d\n", overlap); > exit (1); > } > } > return 0; > } > > ------------------------------------------------------------------------ lbj AT lbjlaptop:/tmp/q $ gcc test.c -o test.exe lbj AT lbjlaptop:/tmp/q $ gcc -mno-cygwin test.c -o test_no-cygwin.exe lbj AT lbjlaptop:/tmp/q $ ./test.exe malloc (16777216) = 6553608 malloc (16777216) = 23396360 malloc (16777216) = 40239112 malloc (16777216) = 57081864 malloc (16777216) = 73924616 malloc (16777216) = 90767368 malloc (16777216) = 107610120 malloc (16777216) = 124452872 malloc (16777216) = 141295624 malloc (16777216) = 570687496 overlap = 4920 lbj AT lbjlaptop:/tmp/q $ ./test_no-cygwin.exe malloc (16777216) = 4456480 lbj AT lbjlaptop:/tmp/q Win2K, 512MB RAM, cygwin 1.3.22. -- Ljubomir Josifovski -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/