summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc/free.c
diff options
context:
space:
mode:
authorMiles Bader <miles@lsi.nec.co.jp>2002-07-25 04:23:28 +0000
committerMiles Bader <miles@lsi.nec.co.jp>2002-07-25 04:23:28 +0000
commit5446f4e74f052ca4fea226a8fdb89502d6520a32 (patch)
tree5f7f39060ee1c1d448690ab9c3d50b10ba8282f5 /libc/stdlib/malloc/free.c
parent79b4ef6e67261d45928f47161e8a3c129310c5c8 (diff)
Miscellaneous tidying-up.
Diffstat (limited to 'libc/stdlib/malloc/free.c')
-rw-r--r--libc/stdlib/malloc/free.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/libc/stdlib/malloc/free.c b/libc/stdlib/malloc/free.c
index f7d8fc18d..3074ff5e6 100644
--- a/libc/stdlib/malloc/free.c
+++ b/libc/stdlib/malloc/free.c
@@ -18,7 +18,7 @@
#include "malloc.h"
#include "heap.h"
-
+
void
free (void *mem)
{
@@ -35,23 +35,23 @@ free (void *mem)
__malloc_lock ();
+ /* Put MEM back in the heap, and get the free-area it was placed in. */
fa = __heap_free (&__malloc_heap, mem, size);
- /* Now we check to see if FA has grown big enough that it should be
+ /* See if the free-area FA has grown big enough that it should be
unmapped. */
if (HEAP_FREE_AREA_SIZE (fa) < MALLOC_UNMAP_THRESHOLD)
- /* Nothing left to do, just release the lock. */
+ /* Nope, nothing left to do, just release the lock. */
__malloc_unlock ();
else
- /* Try to unmap FA. */
+ /* Yup, try to unmap FA. */
{
- unsigned long start, end;
+ unsigned long start = (unsigned long)HEAP_FREE_AREA_START (fa);
+ unsigned long end = (unsigned long)HEAP_FREE_AREA_END (fa);
#ifndef MALLOC_USE_SBRK
unsigned long unmap_start, unmap_end;
#endif
- end = (unsigned long)HEAP_FREE_AREA_END (fa);
-
#ifdef MALLOC_USE_SBRK
/* Get the sbrk lock so that the two possible calls to sbrk below
are guaranteed to be contiguous. */
@@ -68,17 +68,13 @@ free (void *mem)
if ((void *)end != sbrk (0))
{
MALLOC_DEBUG (" not unmapping: 0x%lx - 0x%lx (%d bytes)\n",
- (unsigned long)HEAP_FREE_AREA_START (fa),
- (unsigned long)HEAP_FREE_AREA_END (fa),
- fa->size);
+ start, end, end - start);
__malloc_unlock_sbrk ();
__malloc_unlock ();
return;
}
#endif
- start = (unsigned long)HEAP_FREE_AREA_START (fa);
-
MALLOC_DEBUG (" unmapping: 0x%lx - 0x%lx (%ld bytes)\n",
start, end, end - start);
@@ -136,6 +132,7 @@ free (void *mem)
__malloc_unlock ();
if (unmap_end > unmap_start)
+ /* Finally, actually unmap the memory. */
munmap ((void *)unmap_start, unmap_end - unmap_start);
#endif /* MALLOC_USE_SBRK */