1
0

heap_pre_realloc.c 784 B

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