Returned mail: see transcript for details
Wolfram Gloger
Wolfram.Gloger@dent.med.uni-muenchen.de
Tue Jun 11 02:42:00 GMT 2002
> If you allocate enough memory so that eventually malloc would normally return
> NULL because it can't allocate any more memory, the current version of malloc
> from cvs will cause a segmentation violation (on systems that trap access to
> NULL). This is due to the fact that new_heap returns NULL when it can't
> allocate a new heap. The January 29th rewrite of malloc introduced the bug.
Thanks, this was a copy'n'paste error with respect to braces, AFAICS.
The patch below doesn't add an extra return path and is therefore more
in line with Lea's original sources.
Regards,
Wolfram.
2002-06-11 Wolfram Gloger <wg@malloc.de>
* malloc/malloc.c: Fix error path when new_heap() returns
NULL. Reported by Michael Meissner <meissner@redhat.com>.
--- malloc.c 2002/05/12 21:16:52 1.9
+++ malloc.c 2002/06/11 09:33:59
@@ -2786,20 +2786,17 @@
#endif
set_head(old_top, (((char *)old_heap + old_heap->size) - (char *)old_top)
| PREV_INUSE);
- } else {
- /* A new heap must be created. */
- heap = new_heap(nb + (MINSIZE + sizeof(*heap)), mp_.top_pad);
- if(heap) {
- heap->ar_ptr = av;
- heap->prev = old_heap;
- av->system_mem += heap->size;
- arena_mem += heap->size;
+ }
+ else if ((heap = new_heap(nb + (MINSIZE + sizeof(*heap)), mp_.top_pad))) {
+ /* Use a newly allocated heap. */
+ heap->ar_ptr = av;
+ heap->prev = old_heap;
+ av->system_mem += heap->size;
+ arena_mem += heap->size;
#if 0
- if((unsigned long)(mmapped_mem + arena_mem + sbrked_mem) > max_total_mem)
- max_total_mem = mmapped_mem + arena_mem + sbrked_mem;
+ if((unsigned long)(mmapped_mem + arena_mem + sbrked_mem) > max_total_mem)
+ max_total_mem = mmapped_mem + arena_mem + sbrked_mem;
#endif
- }
-
/* Set up the new top. */
top(av) = chunk_at_offset(heap, sizeof(*heap));
set_head(top(av), (heap->size - sizeof(*heap)) | PREV_INUSE);
More information about the Libc-alpha
mailing list