Add DUSK_TRACK_MEMORY allocation tracker and memoryCheckUnfreed report

memoryAllocate() becomes a macro capturing __FILE__/__LINE__ into a
fixed-size tracking table when DUSK_TRACK_MEMORY is enabled (Linux only
for now), so a leak surviving to shutdown can be traced back to its call
site. Replaces engineDispose's hard assertTrue with memoryCheckUnfreed(),
which reports unfreed allocations (with call sites when tracking is on,
just a count otherwise) instead of aborting.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
2026-09-13 09:19:24 -05:00
co-authored by Claude Sonnet 5
parent 6af0e9cf28
commit 93554b39ba
4 changed files with 160 additions and 2 deletions
+12
View File
@@ -28,6 +28,17 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
set(DUSK_BACKTRACE ON CACHE BOOL "Enable backtrace support for assert failures.")
# Records the file/line of every memoryAllocate() call into a fixed-size
# tracking table (removed again on memoryFree()) so a leak still present at
# engineDispose()'s memoryGetAllocatedCount() check can be traced back to
# where it was allocated. Linux only for now.
set(DUSK_TRACK_MEMORY OFF CACHE BOOL "Track memoryAllocate() call sites to help find memory leaks.")
if(DUSK_TRACK_MEMORY)
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_TRACK_MEMORY
)
endif()
# Define platform-specific macros.
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_SDL2
@@ -45,4 +56,5 @@ target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
DUSK_TIME_DYNAMIC
DUSK_NETWORK_IPV6
DUSK_THREAD_PTHREAD
DUSK_TRACK_MEMORY
)