Ver código fonte

Use new malloc header macros.

Miles Bader 23 anos atrás
pai
commit
a3483a6eb0
2 arquivos alterados com 6 adições e 5 exclusões
  1. 2 2
      libc/stdlib/malloc/free.c
  2. 4 3
      libc/stdlib/malloc/malloc.c

+ 2 - 2
libc/stdlib/malloc/free.c

@@ -28,8 +28,8 @@ free (void *mem)
       struct heap_free_area *fa;
       struct heap *heap = &__malloc_heap;
 
-      mem -= MALLOC_ALIGNMENT;
-      size = *(size_t *)mem;
+      size = MALLOC_SIZE (mem);
+      mem = MALLOC_BASE (mem);
 
       MALLOC_DEBUG ("free: 0x%lx (base = 0x%lx, total_size = %d)\n",
 		    (long)mem + MALLOC_ALIGNMENT, (long)mem, size);

+ 4 - 3
libc/stdlib/malloc/malloc.c

@@ -119,10 +119,11 @@ malloc (size_t size)
   __malloc_unlock ();
 
   if (mem)
-    /* Record the size of this block just before the returned address.  */
+    /* Record the size of this block.  */
     {
-      *(size_t *)mem = size;
-      mem += MALLOC_ALIGNMENT;
+      MALLOC_SET_SIZE (mem, size);
+
+      mem = MALLOC_ADDR (mem);
 
       MALLOC_DEBUG ("  malloc: returning 0x%lx (base:0x%lx, total_size:%d)\n",
 		    (long)mem, (long)mem - MALLOC_ALIGNMENT, size);