diff --git a/minimal_heap_implementation.inl b/minimal_heap_implementation.inl index 627e574..5d4fd30 100644 --- a/minimal_heap_implementation.inl +++ b/minimal_heap_implementation.inl @@ -166,8 +166,10 @@ void* MIHP_Allocate(MIHP_Heap* heap, size_t size) targetSegment->OccupiedSize = size; targetSegment->Checksum = MIHP_GenerateHeapSegmentChecksum(heap, targetSegment); - currentArea->NumOccupiedSegments++; + // Set it to currentSegment as it may be a large segment we've split targetSegment of currentArea->LastSuccessfulAllocationSegment = currentSegment; + + currentArea->NumOccupiedSegments++; currentArea->Checksum = MIHP_GenerateHeapMemoryAreaChecksum(heap, currentArea); heap->Stats.NumTotalOccupiedSegments++; @@ -279,7 +281,7 @@ void* MIHP_Reallocate(MIHP_Heap* heap, void* ptr, size_t newSize) MIHP_HeapSegmentHeader* newSpittedSegment = NULL; MIHP_SplitHeapSegment(heap, segment, newSplitSegmentSize, &newSpittedSegment); if (newSpittedSegment && newSpittedSegment->NextSegment) - MIHP_MergeHeapSegments(heap, newSpittedSegment, newSpittedSegment->NextSegment); + MIHP_MergeHeapSegments(heap, newSpittedSegment, newSpittedSegment->NextSegment); // Try directly merging with the adjacent segment } MIHP_UnlockHeap(heap); diff --git a/minimal_heap_test.c b/minimal_heap_test.c index 2f674d9..5eec170 100644 --- a/minimal_heap_test.c +++ b/minimal_heap_test.c @@ -5,7 +5,7 @@ #include #include -#define USE_MALLOC 1 +#define USE_MALLOC 0 #define MIHP_ValidateHeap(x)