This is the mail archive of the cygwin@cygwin.com 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: 1.3.22-1 on XP: malloc returns overlapping buffers


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




This works OK for me on W2K SP1 with cygwin 1.5.x. Maybe you want to upgrade to this (i.e. the test version) and see if you still see the problem.


-- Larry Hall http://www.rfk.com RFK Partners, Inc. (508) 893-9779 - RFK Office 838 Washington Street (508) 893-9889 - FAX Holliston, MA 01746


################################################################# ################################################################# ################################################################# ##### ##### ##### ################################################################# ################################################################# #################################################################

#################################################################
#################################################################
#################################################################
#####
#####
#####
#################################################################
#################################################################
#################################################################

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


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