delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/08/21/13:54:38

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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
Date: Thu, 21 Aug 2003 18:49:44 +0100
From: Ljubomir Josifovski <lbj AT cre DOT canon DOT co DOT uk>
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
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 <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 -


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