heap_merge_with_next.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <assert.h>
  2. #include "private.h"
  3. /*--------------------------------------------------------- */
  4. lub_heap_status_t
  5. lub_heap_merge_with_next(lub_heap_t *this,
  6. lub_heap_block_t *block)
  7. {
  8. lub_heap_status_t result = LUB_HEAP_FAILED;
  9. lub_heap_block_t *next_block;
  10. assert(0 == block->alloc.tag.free);
  11. do
  12. {
  13. /* see whether there is a free block just after us */
  14. next_block = lub_heap_block_getnext(block);
  15. if( (NULL != next_block )
  16. && (1 == next_block->free.tag.free))
  17. {
  18. if(BOOL_FALSE == lub_heap_block_check(next_block))
  19. {
  20. result = LUB_HEAP_CORRUPTED;
  21. break;
  22. }
  23. lub_heap_graft_to_bottom(this,
  24. next_block,
  25. block,
  26. block->alloc.tag.words,
  27. block->alloc.tag.segment,
  28. block->free.tag.free ? BOOL_TRUE : BOOL_FALSE);
  29. result = LUB_HEAP_OK;
  30. }
  31. } while(0);
  32. return result;
  33. }
  34. /*--------------------------------------------------------- */