SDL: Disable tracking memory allocation counts by default

From 2e4dc9c109330491e787b4b4b09f949fb4347b8e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 21 Dec 2024 05:34:12 -0800
Subject: [PATCH] Disable tracking memory allocation counts by default

Fixes https://github.com/libsdl-org/SDL/issues/11099
---
 src/stdlib/SDL_malloc.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c
index 4cdee69f6861a..72e5354c90459 100644
--- a/src/stdlib/SDL_malloc.c
+++ b/src/stdlib/SDL_malloc.c
@@ -6352,6 +6352,17 @@ static struct
     real_malloc, real_calloc, real_realloc, real_free, { 0 }
 };
 
+// Define this if you want to track the number of allocations active
+// #define TRACK_ALLOCATION_COUNT
+#ifdef TRACK_ALLOCATION_COUNT
+#define INCREMENT_ALLOCATION_COUNT()    (void)SDL_AtomicIncRef(&s_mem.num_allocations)
+#define DECREMENT_ALLOCATION_COUNT()    (void)SDL_AtomicDecRef(&s_mem.num_allocations)
+#else
+#define INCREMENT_ALLOCATION_COUNT()
+#define DECREMENT_ALLOCATION_COUNT()
+#endif
+
+
 void SDL_GetOriginalMemoryFunctions(SDL_malloc_func *malloc_func,
                                     SDL_calloc_func *calloc_func,
                                     SDL_realloc_func *realloc_func,
@@ -6430,7 +6441,7 @@ void *SDL_malloc(size_t size)
 
     mem = s_mem.malloc_func(size);
     if (mem) {
-        SDL_AtomicIncRef(&s_mem.num_allocations);
+        INCREMENT_ALLOCATION_COUNT();
     } else {
         SDL_OutOfMemory();
     }
@@ -6449,7 +6460,7 @@ void *SDL_calloc(size_t nmemb, size_t size)
 
     mem = s_mem.calloc_func(nmemb, size);
     if (mem) {
-        SDL_AtomicIncRef(&s_mem.num_allocations);
+        INCREMENT_ALLOCATION_COUNT();
     } else {
         SDL_OutOfMemory();
     }
@@ -6467,7 +6478,7 @@ void *SDL_realloc(void *ptr, size_t size)
 
     mem = s_mem.realloc_func(ptr, size);
     if (mem && !ptr) {
-        SDL_AtomicIncRef(&s_mem.num_allocations);
+        INCREMENT_ALLOCATION_COUNT();
     } else if (!mem) {
         SDL_OutOfMemory();
     }
@@ -6482,5 +6493,5 @@ void SDL_free(void *ptr)
     }
 
     s_mem.free_func(ptr);
-    (void)SDL_AtomicDecRef(&s_mem.num_allocations);
+    DECREMENT_ALLOCATION_COUNT();
 }