free.c 791 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * libc/stdlib/malloc-zarg/free.c -- free function
  3. *
  4. * Copyright (C) 2002 NEC Corporation
  5. * Copyright (C) 2002 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU Lesser
  8. * General Public License. See the file COPYING.LIB in the main
  9. * directory of this archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #include <stdlib.h>
  14. #include <sys/mman.h>
  15. #include "malloc.h"
  16. #include "heap.h"
  17. void free (void *mem)
  18. {
  19. size_t size;
  20. mem = (size_t *)mem - 1;
  21. size = *(size_t *)mem;
  22. MALLOC_DEBUG ("free: 0x%lx (base = 0x%lx, total_size = %d)\n",
  23. (long)mem + sizeof (size_t), (long)mem, size);
  24. if (size >= MALLOC_MMAP_THRESHOLD)
  25. munmap (mem, size);
  26. else
  27. __heap_free (&__malloc_heap, mem, size);
  28. }