1
0

heap_pre_realloc.c 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <string.h>
  2. #include "private.h"
  3. #include "context.h"
  4. #include "node.h"
  5. /*
  6. * This function
  7. */
  8. void
  9. lub_heap_pre_realloc(lub_heap_t *this,
  10. char **ptr,
  11. size_t *size)
  12. {
  13. if(*ptr)
  14. {
  15. /* is this a pointer to a node in the "leak" trees? */
  16. lub_heap_node_t *node = lub_heap_node_from_start_of_block_ptr(*ptr);
  17. if(NULL != node)
  18. {
  19. lub_heap_node_fini(node);
  20. /* move the pointer to the start of the block */
  21. *ptr = (char*)node;
  22. }
  23. }
  24. if((0 < lub_heap_frame_count))
  25. {
  26. size_t old_size = *size;
  27. if(old_size)
  28. {
  29. /* allocate enough bytes for a node */
  30. *size += lub_heap_node__get_instanceSize();
  31. if(*size < old_size)
  32. {
  33. /* we've wrapped the size variable
  34. * make sure we fail the allocation
  35. */
  36. *size = (size_t)-1;
  37. }
  38. }
  39. }
  40. }