From 847dfe1484920635fc9ab8e3f2390c7d957f7c44 Mon Sep 17 00:00:00 2001 From: ToyB-Chan Date: Tue, 9 Jun 2026 20:37:30 +0200 Subject: [PATCH] rename and fixed missing unlock --- minimal_heap.h | 2 +- minimal_heap_implementation.inl | 7 +++++-- minimal_heap_test.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/minimal_heap.h b/minimal_heap.h index 5a92d2a..6fe261b 100644 --- a/minimal_heap.h +++ b/minimal_heap.h @@ -124,7 +124,7 @@ bool MIHP_IsHeapInitialized(const MIHP_Heap* heap); bool MIHP_UninitializeHeap(MIHP_Heap* heap, bool force); void* MIHP_Allocate(MIHP_Heap* heap, size_t size); -void* MIHP_Realloc(MIHP_Heap* heap, void* ptr, size_t newSize); +void* MIHP_Reallocate(MIHP_Heap* heap, void* ptr, size_t newSize); bool MIHP_Free(MIHP_Heap* heap, void* ptr); bool MIHP_IsPointerInHeap(MIHP_Heap* heap, void* ptr); diff --git a/minimal_heap_implementation.inl b/minimal_heap_implementation.inl index 6fe763e..aba3bb7 100644 --- a/minimal_heap_implementation.inl +++ b/minimal_heap_implementation.inl @@ -150,7 +150,10 @@ AllocateNewArea: MIHP_HeapMemoryAreaHeader* newArea = MIHP_CreateHeapMemoryArea(heap, newAreaSize); if (newArea == NULL) + { + MIHP_UNLOCK_HEAP(&heap->HeapLock); return NULL; + } newArea->NextArea = heap->FirstArea; heap->FirstArea->PreviousArea = newArea; @@ -164,7 +167,7 @@ AllocateNewArea: return MIHP_Allocate(heap, size); } -void* MIHP_Realloc(MIHP_Heap* heap, void* ptr, size_t newSize) +void* MIHP_Reallocate(MIHP_Heap* heap, void* ptr, size_t newSize) { if (newSize == 0) { @@ -203,7 +206,7 @@ void* MIHP_Realloc(MIHP_Heap* heap, void* ptr, size_t newSize) if (segment->NextSegment && MIHP_MergeHeapSegments(segment, segment->NextSegment)) { MIHP_UNLOCK_HEAP(&heap->HeapLock); - return MIHP_Realloc(heap, ptr, newSize); + return MIHP_Reallocate(heap, ptr, newSize); } MIHP_UNLOCK_HEAP(&heap->HeapLock); diff --git a/minimal_heap_test.c b/minimal_heap_test.c index 3048126..67b41fa 100644 --- a/minimal_heap_test.c +++ b/minimal_heap_test.c @@ -81,7 +81,7 @@ int main() #if USE_MALLOC myptrs[i] = realloc(myptrs[i], size); #else - myptrs[i] = MIHP_Realloc(&myHeap, myptrs[i], size); + myptrs[i] = MIHP_Reallocate(&myHeap, myptrs[i], size); MIHP_ValidateHeap(&myHeap);