Mail Archives: cygwin/2003/08/21/13:54:38
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 <stdio.h>
> #include <stdlib.h>
>
> 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/
- Raw text -