You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * This file is a part of SMalloc.
  3. * SMalloc is MIT licensed.
  4. * Copyright (c) 2017 Andrey Rys.
  5. */
  6. #include "smalloc_i.h"
  7. void sm_free_pool(struct smalloc_pool *spool, void *p)
  8. {
  9. struct smalloc_hdr *shdr;
  10. char *s;
  11. if (!smalloc_verify_pool(spool)) {
  12. errno = EINVAL;
  13. return;
  14. }
  15. if (!p) return;
  16. shdr = USER_TO_HEADER(p);
  17. if (smalloc_is_alloc(spool, shdr)) {
  18. if (spool->do_zero) memset(p, 0, shdr->rsz);
  19. s = CHAR_PTR(p);
  20. s += shdr->usz;
  21. memset(s, 0, HEADER_SZ);
  22. if (spool->do_zero) memset(s+HEADER_SZ, 0, shdr->rsz - shdr->usz);
  23. memset(shdr, 0, HEADER_SZ);
  24. return;
  25. }
  26. smalloc_UB(spool, p);
  27. return;
  28. }
  29. void sm_free(void *p)
  30. {
  31. sm_free_pool(&smalloc_curr_pool, p);
  32. }