/* Output a text representation of HEAP to stderr, labelling it with STR. */ void __heap_dump (struct heap_free_area *heap, const char *str) { static smallint recursed; if (! recursed) { __heap_check (heap, str); recursed = 1; __malloc_debug_printf (1, "%s: heap @0x%lx:", str, (long)heap); __heap_dump_freelist (heap); __malloc_debug_indent (-1); recursed = 0; } }
/* Output a text representation of HEAP to stderr, labelling it with STR. */ void __heap_dump (struct heap *heap, const char *str) { static int recursed = 0; if (! recursed) { __heap_check (heap, str); recursed = 1; #ifdef MALLOC_DEBUGGING __malloc_debug_printf (1, "%s: heap @0x%lx:", str, (long)heap); #endif __heap_dump_freelist (heap); #ifdef MALLOC_DEBUGGING __malloc_debug_indent (-1); #endif recursed = 0; } }
void * malloc (size_t size) { void *mem; #ifdef MALLOC_DEBUGGING static smallint debugging_initialized; if (! debugging_initialized) { debugging_initialized = 1; __malloc_debug_init (); } if (__malloc_check) __heap_check (__malloc_heap, "malloc"); #endif #ifdef __MALLOC_GLIBC_COMPAT__ if (unlikely (size == 0)) size++; #else /* Some programs will call malloc (0). Lets be strict and return NULL */ if (unlikely (size == 0)) goto oom; #endif /* Check if they are doing something dumb like malloc(-1) */ if (unlikely(((unsigned long)size > (unsigned long)(MALLOC_HEADER_SIZE*-2)))) goto oom; mem = malloc_from_heap (size, &__malloc_heap, &__malloc_heap_lock); if (unlikely (!mem)) { oom: __set_errno (ENOMEM); return 0; } return mem; }