From 0f639ba3b1f1054efcaac45dd5ce02d2ae3a6a8b Mon Sep 17 00:00:00 2001 From: IlushaShurupov Date: Mon, 24 Jul 2023 20:39:28 +0300 Subject: [PATCH] Freeze on no memory available --- Allocators/private/HeapAllocatorGlobal.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Allocators/private/HeapAllocatorGlobal.cpp b/Allocators/private/HeapAllocatorGlobal.cpp index c2ea8a4..7e41c6a 100644 --- a/Allocators/private/HeapAllocatorGlobal.cpp +++ b/Allocators/private/HeapAllocatorGlobal.cpp @@ -6,6 +6,7 @@ #include "Utils.hpp" #include "Debugging.hpp" +#include #include using namespace tp; @@ -66,13 +67,17 @@ void* HeapAllocGlobal::allocate(ualni aBlockSize) { } // 1) Allocate the block + ALLOCATE: auto head = (MemHead*)malloc(aBlockSize + WRAP_SIZE * 2 + HEAD_SIZE); + if (!head) { + printf("WARNING : Cant allocate memory. Trying again\n"); + goto ALLOCATE; // Just freeze if no memory is available + } + auto wrap_top = (int1*)(head + 1); auto data = wrap_top + WRAP_SIZE; auto wrap_bottom = data + aBlockSize; - if (!head) { return nullptr; } - head->mBlockSize = aBlockSize; head->mIgnored = mIgnore;