From 1e1d80110eeb129ece00c10689591fa50e866e2b Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 10 Apr 2026 21:16:47 +0200
Subject: [PATCH] test: cannot access tracked allocation node without lock
This fixes a SIGSEGV error under mulithreading.
---
src/test/SDL_test_memory.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/test/SDL_test_memory.c b/src/test/SDL_test_memory.c
index d099c668c3dae..11b762e5d311a 100644
--- a/src/test/SDL_test_memory.c
+++ b/src/test/SDL_test_memory.c
@@ -95,31 +95,36 @@ static unsigned int get_allocation_bucket(void *mem)
return index;
}
-static SDL_tracked_allocation *SDL_GetTrackedAllocation(void *mem)
+static bool SDL_GetTrackedAllocation(void *mem, size_t *entry_size)
{
SDL_tracked_allocation *entry;
LOCK_ALLOCATOR();
int index = get_allocation_bucket(mem);
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
if (mem == entry->mem) {
+ if (entry_size) {
+ *entry_size = entry->size;
+ }
UNLOCK_ALLOCATOR();
- return entry;
+ return true;
}
}
UNLOCK_ALLOCATOR();
- return NULL;
+ return false;
}
static size_t SDL_GetTrackedAllocationSize(void *mem)
{
- SDL_tracked_allocation *entry = SDL_GetTrackedAllocation(mem);
-
- return entry ? entry->size : SIZE_MAX;
+ size_t size = 0;
+ if (!SDL_GetTrackedAllocation(mem, &size)) {
+ size = SIZE_MAX;
+ }
+ return size;
}
static bool SDL_IsAllocationTracked(void *mem)
{
- return SDL_GetTrackedAllocation(mem) != NULL;
+ return SDL_GetTrackedAllocation(mem, NULL);
}
static void SDL_TrackAllocation(void *mem, size_t size)