[PATCH] Fix malloc

Wolfram Gloger wmglo@dent.med.uni-muenchen.de
Wed Mar 13 04:11:00 GMT 2002


Hi,

> The issue is that if MORECORE_FAILURE != MMAP_FAILED, then
> if brk fails and mmap fails too, it would leave brk set to MMAP_FAILED
> and so code below would consider it as if brk was successfully set.

Clearly you're right.  I'd rather not change 'brk' at all though,
like below:

2002-03-13  Wolfram Gloger  <wg@malloc.de>

	* malloc/malloc.c (sYSMALLOc): Don't change brk if mmap
	failed.

--- malloc.c	2002/02/15 09:30:28	1.6
+++ malloc.c	2002/03/13 12:06:55
@@ -2824,11 +2824,12 @@
     /* Don't try if size wraps around 0 */
     if ((unsigned long)(size) > (unsigned long)(nb)) {
 
-      brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));
+      char *mbrk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));
 
-      if (brk != MAP_FAILED) {
+      if (mbrk != MAP_FAILED) {
 
         /* We do not need, and cannot use, another sbrk call to find end */
+        brk = mbrk;
         snd_brk = brk + size;
 
         /*



More information about the Libc-hacker mailing list