summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/malloc-standard
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/malloc-standard')
-rw-r--r--libc/stdlib/malloc-standard/calloc.c6
-rw-r--r--libc/stdlib/malloc-standard/free.c4
-rw-r--r--libc/stdlib/malloc-standard/mallinfo.c45
-rw-r--r--libc/stdlib/malloc-standard/malloc.c95
-rw-r--r--libc/stdlib/malloc-standard/malloc.h15
-rw-r--r--libc/stdlib/malloc-standard/mallopt.c4
-rw-r--r--libc/stdlib/malloc-standard/memalign.c18
-rw-r--r--libc/stdlib/malloc-standard/realloc.c36
8 files changed, 124 insertions, 99 deletions
diff --git a/libc/stdlib/malloc-standard/calloc.c b/libc/stdlib/malloc-standard/calloc.c
index 99e8884ad..80ba3d04a 100644
--- a/libc/stdlib/malloc-standard/calloc.c
+++ b/libc/stdlib/malloc-standard/calloc.c
@@ -16,7 +16,7 @@
#include "malloc.h"
-libc_hidden_proto(memset)
+/* Experimentally off - libc_hidden_proto(memset) */
/* ------------------------------ calloc ------------------------------ */
void* calloc(size_t n_elements, size_t elem_size)
@@ -36,7 +36,7 @@ void* calloc(size_t n_elements, size_t elem_size)
return NULL;
}
- LOCK;
+ __MALLOC_LOCK;
mem = malloc(size);
if (mem != 0) {
p = mem2chunk(mem);
@@ -88,7 +88,7 @@ void* calloc(size_t n_elements, size_t elem_size)
}
#endif
}
- UNLOCK;
+ __MALLOC_UNLOCK;
return mem;
}
diff --git a/libc/stdlib/malloc-standard/free.c b/libc/stdlib/malloc-standard/free.c
index e0c6ef061..4d24697be 100644
--- a/libc/stdlib/malloc-standard/free.c
+++ b/libc/stdlib/malloc-standard/free.c
@@ -282,7 +282,7 @@ void free(void* mem)
if (mem == NULL)
return;
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
p = mem2chunk(mem);
size = chunksize(p);
@@ -406,6 +406,6 @@ void free(void* mem)
av->mmapped_mem -= (size + offset);
munmap((char*)p - offset, size + offset);
}
- UNLOCK;
+ __MALLOC_UNLOCK;
}
diff --git a/libc/stdlib/malloc-standard/mallinfo.c b/libc/stdlib/malloc-standard/mallinfo.c
index 4f274ed32..18331010a 100644
--- a/libc/stdlib/malloc-standard/mallinfo.c
+++ b/libc/stdlib/malloc-standard/mallinfo.c
@@ -32,7 +32,7 @@ struct mallinfo mallinfo(void)
int nblocks;
int nfastblocks;
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
/* Ensure initialization */
if (av->top == 0) {
@@ -77,7 +77,7 @@ struct mallinfo mallinfo(void)
mi.fsmblks = fastavail;
mi.keepcost = chunksize(av->top);
mi.usmblks = av->max_total_mem;
- UNLOCK;
+ __MALLOC_UNLOCK;
return mi;
}
libc_hidden_def(mallinfo)
@@ -91,19 +91,36 @@ void malloc_stats(FILE *file)
}
mi = mallinfo();
- fprintf(file, "total bytes allocated = %10u\n", (unsigned int)(mi.arena + mi.hblkhd));
- fprintf(file, "total bytes in use bytes = %10u\n", (unsigned int)(mi.uordblks + mi.hblkhd));
- fprintf(file, "total non-mmapped bytes allocated = %10d\n", mi.arena);
- fprintf(file, "number of mmapped regions = %10d\n", mi.hblks);
- fprintf(file, "total allocated mmap space = %10d\n", mi.hblkhd);
- fprintf(file, "total allocated sbrk space = %10d\n", mi.uordblks);
+ fprintf(file,
+ "total bytes allocated = %10u\n"
+ "total bytes in use bytes = %10u\n"
+ "total non-mmapped bytes allocated = %10d\n"
+ "number of mmapped regions = %10d\n"
+ "total allocated mmap space = %10d\n"
+ "total allocated sbrk space = %10d\n"
#if 0
- fprintf(file, "number of free chunks = %10d\n", mi.ordblks);
- fprintf(file, "number of fastbin blocks = %10d\n", mi.smblks);
- fprintf(file, "space in freed fastbin blocks = %10d\n", mi.fsmblks);
+ "number of free chunks = %10d\n"
+ "number of fastbin blocks = %10d\n"
+ "space in freed fastbin blocks = %10d\n"
#endif
- fprintf(file, "maximum total allocated space = %10d\n", mi.usmblks);
- fprintf(file, "total free space = %10d\n", mi.fordblks);
- fprintf(file, "memory releasable via malloc_trim = %10d\n", mi.keepcost);
+ "maximum total allocated space = %10d\n"
+ "total free space = %10d\n"
+ "memory releasable via malloc_trim = %10d\n",
+
+ (unsigned int)(mi.arena + mi.hblkhd),
+ (unsigned int)(mi.uordblks + mi.hblkhd),
+ mi.arena,
+ mi.hblks,
+ mi.hblkhd,
+ mi.uordblks,
+#if 0
+ mi.ordblks,
+ mi.smblks,
+ mi.fsmblks,
+#endif
+ mi.usmblks,
+ mi.fordblks,
+ mi.keepcost
+ );
}
diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c
index 0dc208fb6..3253ebda6 100644
--- a/libc/stdlib/malloc-standard/malloc.c
+++ b/libc/stdlib/malloc-standard/malloc.c
@@ -17,9 +17,7 @@
#include "malloc.h"
-#ifdef __UCLIBC_HAS_THREADS__
-pthread_mutex_t __malloc_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
+__UCLIBC_MUTEX_INIT(__malloc_lock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
/*
There is exactly one instance of this struct in this malloc.
@@ -33,7 +31,7 @@ struct malloc_state __malloc_state; /* never directly referenced */
/* forward declaration */
static int __malloc_largebin_index(unsigned int sz);
-#ifdef __MALLOC_DEBUGGING
+#ifdef __UCLIBC_MALLOC_DEBUGGING__
/*
Debugging support
@@ -43,21 +41,21 @@ static int __malloc_largebin_index(unsigned int sz);
programs. This can be very effective (albeit in an annoying way)
in helping track down dangling pointers.
- If you compile with -D__MALLOC_DEBUGGING, a number of assertion checks are
+ If you compile with __UCLIBC_MALLOC_DEBUGGING__, a number of assertion checks are
enabled that will catch more memory errors. You probably won't be
able to make much sense of the actual assertion errors, but they
should help you locate incorrectly overwritten memory. The
checking is fairly extensive, and will slow down execution
- noticeably. Calling malloc_stats or mallinfo with __MALLOC_DEBUGGING set will
+ noticeably. Calling malloc_stats or mallinfo with __UCLIBC_MALLOC_DEBUGGING__ set will
attempt to check every non-mmapped allocated and free chunk in the
course of computing the summmaries. (By nature, mmapped regions
cannot be checked very much automatically.)
- Setting __MALLOC_DEBUGGING may also be helpful if you are trying to modify
+ Setting __UCLIBC_MALLOC_DEBUGGING__ may also be helpful if you are trying to modify
this code. The assertions in the check routines spell out in more
detail the assumptions and invariants underlying the algorithms.
- Setting __MALLOC_DEBUGGING does NOT provide an automated mechanism for checking
+ Setting __UCLIBC_MALLOC_DEBUGGING__ does NOT provide an automated mechanism for checking
that all accesses to malloced memory stay within their
bounds. However, there are several add-ons and adaptations of this
or other mallocs available that do this.
@@ -351,7 +349,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
char* old_end; /* its end address */
long size; /* arg to first MORECORE or mmap call */
- char* brk; /* return value from MORECORE */
+ char* fst_brk; /* return value from MORECORE */
long correction; /* arg to 2nd MORECORE call */
char* snd_brk; /* 2nd return val */
@@ -455,7 +453,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
old_size = chunksize(old_top);
old_end = (char*)(chunk_at_offset(old_top, old_size));
- brk = snd_brk = (char*)(MORECORE_FAILURE);
+ fst_brk = snd_brk = (char*)(MORECORE_FAILURE);
/* If not the first time through, we require old_size to
* be at least MINSIZE and to have prev_inuse set. */
@@ -501,7 +499,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
*/
if (size > 0)
- brk = (char*)(MORECORE(size));
+ fst_brk = (char*)(MORECORE(size));
/*
If have mmap, try using it as a backup when MORECORE fails or
@@ -512,7 +510,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
segregated mmap region.
*/
- if (brk == (char*)(MORECORE_FAILURE)) {
+ if (fst_brk == (char*)(MORECORE_FAILURE)) {
/* Cannot merge with old top, so add its size back in */
if (contiguous(av))
@@ -525,12 +523,12 @@ static void* __malloc_alloc(size_t nb, mstate av)
/* Don't try if size wraps around 0 */
if ((unsigned long)(size) > (unsigned long)(nb)) {
- brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE));
+ fst_brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE));
- if (brk != (char*)(MORECORE_FAILURE)) {
+ if (fst_brk != (char*)(MORECORE_FAILURE)) {
/* We do not need, and cannot use, another sbrk call to find end */
- snd_brk = brk + size;
+ snd_brk = fst_brk + size;
/* Record that we no longer have a contiguous sbrk region.
After the first time mmap is used as backup, we do not
@@ -542,14 +540,14 @@ static void* __malloc_alloc(size_t nb, mstate av)
}
}
- if (brk != (char*)(MORECORE_FAILURE)) {
+ if (fst_brk != (char*)(MORECORE_FAILURE)) {
av->sbrked_mem += size;
/*
If MORECORE extends previous space, we can likewise extend top size.
*/
- if (brk == old_end && snd_brk == (char*)(MORECORE_FAILURE)) {
+ if (fst_brk == old_end && snd_brk == (char*)(MORECORE_FAILURE)) {
set_head(old_top, (size + old_size) | PREV_INUSE);
}
@@ -576,7 +574,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
front_misalign = 0;
end_misalign = 0;
correction = 0;
- aligned_brk = brk;
+ aligned_brk = fst_brk;
/*
If MORECORE returns an address lower than we have seen before,
@@ -586,7 +584,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
malloc or by other threads. We cannot guarantee to detect
these in all cases, but cope with the ones we do detect.
*/
- if (contiguous(av) && old_size != 0 && brk < old_end) {
+ if (contiguous(av) && old_size != 0 && fst_brk < old_end) {
set_noncontiguous(av);
}
@@ -597,11 +595,11 @@ static void* __malloc_alloc(size_t nb, mstate av)
to foreign calls) but treat them as part of our space for
stats reporting. */
if (old_size != 0)
- av->sbrked_mem += brk - old_end;
+ av->sbrked_mem += fst_brk - old_end;
/* Guarantee alignment of first new chunk made from this space */
- front_misalign = (size_t)chunk2mem(brk) & MALLOC_ALIGN_MASK;
+ front_misalign = (size_t)chunk2mem(fst_brk) & MALLOC_ALIGN_MASK;
if (front_misalign > 0) {
/*
@@ -624,7 +622,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
correction += old_size;
/* Extend the end address to hit a page boundary */
- end_misalign = (size_t)(brk + size + correction);
+ end_misalign = (size_t)(fst_brk + size + correction);
correction += ((end_misalign + pagemask) & ~pagemask) - end_misalign;
assert(correction >= 0);
@@ -638,7 +636,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
correction = 0;
snd_brk = (char*)(MORECORE(0));
}
- else if (snd_brk < brk) {
+ else if (snd_brk < fst_brk) {
/*
If the second call gives noncontiguous space even though
it says it won't, the only course of action is to ignore
@@ -651,7 +649,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
there is no reliable way to detect a noncontiguity
producing a forward gap for the second call.
*/
- snd_brk = brk + size;
+ snd_brk = fst_brk + size;
correction = 0;
set_noncontiguous(av);
}
@@ -661,12 +659,12 @@ static void* __malloc_alloc(size_t nb, mstate av)
/* handle non-contiguous cases */
else {
/* MORECORE/mmap must correctly align */
- assert(aligned_OK(chunk2mem(brk)));
+ assert(aligned_OK(chunk2mem(fst_brk)));
/* Find out current end of memory */
if (snd_brk == (char*)(MORECORE_FAILURE)) {
snd_brk = (char*)(MORECORE(0));
- av->sbrked_mem += snd_brk - brk - size;
+ av->sbrked_mem += snd_brk - fst_brk - size;
}
}
@@ -825,6 +823,7 @@ void* malloc(size_t bytes)
mchunkptr fwd; /* misc temp for linking */
mchunkptr bck; /* misc temp for linking */
void * sysmem;
+ void * retval;
#if !defined(__MALLOC_GLIBC_COMPAT__)
if (!bytes) {
@@ -833,7 +832,7 @@ void* malloc(size_t bytes)
}
#endif
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
/*
Convert request size to internal form by adding (sizeof(size_t)) bytes
@@ -864,8 +863,8 @@ void* malloc(size_t bytes)
if ( (victim = *fb) != 0) {
*fb = victim->fd;
check_remalloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
@@ -888,8 +887,8 @@ void* malloc(size_t bytes)
bck->fd = bin;
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
@@ -945,8 +944,8 @@ void* malloc(size_t bytes)
set_foot(remainder, remainder_size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* remove from unsorted list */
@@ -958,8 +957,8 @@ void* malloc(size_t bytes)
if (size == nb) {
set_inuse_bit_at_offset(victim, size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* place chunk in bin */
@@ -1022,8 +1021,8 @@ void* malloc(size_t bytes)
if (remainder_size < MINSIZE) {
set_inuse_bit_at_offset(victim, size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* Split */
else {
@@ -1034,8 +1033,8 @@ void* malloc(size_t bytes)
set_head(remainder, remainder_size | PREV_INUSE);
set_foot(remainder, remainder_size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
}
@@ -1103,8 +1102,8 @@ void* malloc(size_t bytes)
if (remainder_size < MINSIZE) {
set_inuse_bit_at_offset(victim, size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* Split */
@@ -1121,8 +1120,8 @@ void* malloc(size_t bytes)
set_head(remainder, remainder_size | PREV_INUSE);
set_foot(remainder, remainder_size);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
}
}
@@ -1154,13 +1153,15 @@ use_top:
set_head(remainder, remainder_size | PREV_INUSE);
check_malloced_chunk(victim, nb);
- UNLOCK;
- return chunk2mem(victim);
+ retval = chunk2mem(victim);
+ goto DONE;
}
/* If no space in top, relay to handle system-dependent cases */
sysmem = __malloc_alloc(nb, av);
- UNLOCK;
- return sysmem;
+ retval = sysmem;
+DONE:
+ __MALLOC_UNLOCK;
+ return retval;
}
diff --git a/libc/stdlib/malloc-standard/malloc.h b/libc/stdlib/malloc-standard/malloc.h
index 453d69736..389f1f7d4 100644
--- a/libc/stdlib/malloc-standard/malloc.h
+++ b/libc/stdlib/malloc-standard/malloc.h
@@ -22,18 +22,17 @@
#include <malloc.h>
#include <stdlib.h>
#include <sys/mman.h>
+#include <bits/uClibc_mutex.h>
libc_hidden_proto(mmap)
libc_hidden_proto(sysconf)
libc_hidden_proto(sbrk)
libc_hidden_proto(abort)
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-extern pthread_mutex_t __malloc_lock;
-#endif
-#define LOCK __pthread_mutex_lock(&__malloc_lock)
-#define UNLOCK __pthread_mutex_unlock(&__malloc_lock)
+
+__UCLIBC_MUTEX_EXTERN(__malloc_lock);
+#define __MALLOC_LOCK __UCLIBC_MUTEX_LOCK(__malloc_lock)
+#define __MALLOC_UNLOCK __UCLIBC_MUTEX_UNLOCK(__malloc_lock)
@@ -925,7 +924,7 @@ extern struct malloc_state __malloc_state; /* never directly referenced */
At most one "call" to get_malloc_state is made per invocation of
the public versions of malloc and free, but other routines
that in turn invoke malloc and/or free may call more then once.
- Also, it is called in check* routines if __MALLOC_DEBUGGING is set.
+ Also, it is called in check* routines if __UCLIBC_MALLOC_DEBUGGING__ is set.
*/
#define get_malloc_state() (&(__malloc_state))
@@ -935,7 +934,7 @@ void __malloc_consolidate(mstate) attribute_hidden;
/* Debugging support */
-#if ! __MALLOC_DEBUGGING
+#ifndef __UCLIBC_MALLOC_DEBUGGING__
#define check_chunk(P)
#define check_free_chunk(P)
diff --git a/libc/stdlib/malloc-standard/mallopt.c b/libc/stdlib/malloc-standard/mallopt.c
index e28792099..053242dbe 100644
--- a/libc/stdlib/malloc-standard/mallopt.c
+++ b/libc/stdlib/malloc-standard/mallopt.c
@@ -25,7 +25,7 @@ int mallopt(int param_number, int value)
ret = 0;
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
/* Ensure initialization/consolidation */
__malloc_consolidate(av);
@@ -58,7 +58,7 @@ int mallopt(int param_number, int value)
ret = 1;
break;
}
- UNLOCK;
+ __MALLOC_UNLOCK;
return ret;
}
diff --git a/libc/stdlib/malloc-standard/memalign.c b/libc/stdlib/malloc-standard/memalign.c
index 27502893d..7e0674be5 100644
--- a/libc/stdlib/malloc-standard/memalign.c
+++ b/libc/stdlib/malloc-standard/memalign.c
@@ -35,6 +35,7 @@ void* memalign(size_t alignment, size_t bytes)
mchunkptr remainder; /* spare room at end to split off */
unsigned long remainder_size; /* its size */
size_t size;
+ void *retval;
/* If need less alignment than we give anyway, just relay to malloc */
@@ -51,7 +52,7 @@ void* memalign(size_t alignment, size_t bytes)
alignment = a;
}
- LOCK;
+ __MALLOC_LOCK;
checked_request2size(bytes, nb);
/* Strategy: find a spot within that chunk that meets the alignment
@@ -63,8 +64,8 @@ void* memalign(size_t alignment, size_t bytes)
m = (char*)(malloc(nb + alignment + MINSIZE));
if (m == 0) {
- UNLOCK;
- return 0; /* propagate failure */
+ retval = 0; /* propagate failure */
+ goto DONE;
}
p = mem2chunk(m);
@@ -92,8 +93,8 @@ void* memalign(size_t alignment, size_t bytes)
if (chunk_is_mmapped(p)) {
newp->prev_size = p->prev_size + leadsize;
set_head(newp, newsize|IS_MMAPPED);
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
/* Otherwise, give back leader, use the rest */
@@ -120,7 +121,10 @@ void* memalign(size_t alignment, size_t bytes)
}
check_inuse_chunk(p);
- UNLOCK;
- return chunk2mem(p);
+ retval = chunk2mem(p);
+
+ DONE:
+ __MALLOC_UNLOCK;
+ return retval;
}
diff --git a/libc/stdlib/malloc-standard/realloc.c b/libc/stdlib/malloc-standard/realloc.c
index f25d6d989..41cae43d1 100644
--- a/libc/stdlib/malloc-standard/realloc.c
+++ b/libc/stdlib/malloc-standard/realloc.c
@@ -17,7 +17,7 @@
#include "malloc.h"
libc_hidden_proto(mremap)
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
/* ------------------------------ realloc ------------------------------ */
void* realloc(void* oldmem, size_t bytes)
@@ -46,6 +46,7 @@ void* realloc(void* oldmem, size_t bytes)
size_t* s; /* copy source */
size_t* d; /* copy destination */
+ void *retval;
/* Check for special cases. */
if (! oldmem)
@@ -55,7 +56,7 @@ void* realloc(void* oldmem, size_t bytes)
return NULL;
}
- LOCK;
+ __MALLOC_LOCK;
av = get_malloc_state();
checked_request2size(bytes, nb);
@@ -82,8 +83,8 @@ void* realloc(void* oldmem, size_t bytes)
set_head_size(oldp, nb);
av->top = chunk_at_offset(oldp, nb);
set_head(av->top, (newsize - nb) | PREV_INUSE);
- UNLOCK;
- return chunk2mem(oldp);
+ retval = chunk2mem(oldp);
+ goto DONE;
}
/* Try to expand forward into next chunk; split off remainder below */
@@ -99,8 +100,8 @@ void* realloc(void* oldmem, size_t bytes)
else {
newmem = malloc(nb - MALLOC_ALIGN_MASK);
if (newmem == 0) {
- UNLOCK;
- return 0; /* propagate failure */
+ retval = 0; /* propagate failure */
+ goto DONE;
}
newp = mem2chunk(newmem);
@@ -149,8 +150,8 @@ void* realloc(void* oldmem, size_t bytes)
free(oldmem);
check_inuse_chunk(newp);
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
}
}
@@ -175,8 +176,8 @@ void* realloc(void* oldmem, size_t bytes)
}
check_inuse_chunk(newp);
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
/*
@@ -194,8 +195,8 @@ void* realloc(void* oldmem, size_t bytes)
/* don't need to remap if still within same page */
if (oldsize == newsize - offset) {
- UNLOCK;
- return oldmem;
+ retval = oldmem;
+ goto DONE;
}
cp = (char*)mremap((char*)oldp - offset, oldsize + offset, newsize, 1);
@@ -216,8 +217,8 @@ void* realloc(void* oldmem, size_t bytes)
if (sum > (unsigned long)(av->max_total_mem))
av->max_total_mem = sum;
- UNLOCK;
- return chunk2mem(newp);
+ retval = chunk2mem(newp);
+ goto DONE;
}
/* Note the extra (sizeof(size_t)) overhead. */
@@ -231,8 +232,11 @@ void* realloc(void* oldmem, size_t bytes)
free(oldmem);
}
}
- UNLOCK;
- return newmem;
+ retval = newmem;
}
+
+ DONE:
+ __MALLOC_UNLOCK;
+ return retval;
}