diff --git a/src/malloc.c b/src/malloc.c index 95d41fbb97..f4f079f30a 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -101,6 +101,11 @@ void *AllocInternal(void *heapStart, u32 size, const char *location) while (block != head); Test_ExitWithResult(TEST_RESULT_ERROR, SourceLine(0), ":L%s:%d, %s: OOM allocating %d bytes", gTestRunnerState.test->filename, SourceLine(0), location, size); #endif + if (location) + { + DebugPrintfLevel(MGBA_LOG_ERROR, "%s: out of memory trying to allocate %d bytes", location, size); + } + AGB_ASSERT(FALSE); return NULL; } @@ -114,6 +119,8 @@ void FreeInternal(void *heapStart, void *pointer) { struct MemBlock *head = (struct MemBlock *)heapStart; struct MemBlock *block = (struct MemBlock *)((u8 *)pointer - sizeof(struct MemBlock)); + AGB_ASSERT(block->magic == MALLOC_SYSTEM_ID); + AGB_ASSERT(block->allocated == TRUE); block->allocated = FALSE; // If the freed block isn't the last one, merge with the next block @@ -136,6 +143,8 @@ void FreeInternal(void *heapStart, void *pointer) { if (!block->prev->allocated) { + AGB_ASSERT(block->prev->magic == MALLOC_SYSTEM_ID); + block->prev->next = block->next; if (block->next != head)