When I call backtrace_symbols() or backtrace_symbols_fd() valgrind rapports 6,452 bytes definitely lost in 11 blocks. This is inside a SDL3 application using SDL_MAIN_USE_CALLBACKS.
Have any of you noticed the same problem? Is this a false positive rapport related to how SDL3 handles stack unwinding internally?
Idk exactly why but using SDL_free() instead of free() to clear string array returned by backtrace_symbols() fixes this problem. backtrace_symbols_fd() use free() internally so that’s probably why it leaks.
I thought SDL_free() is just an alias to free() but turns out I need to dig deeper into SDL3 source.
SDL_free and other memory functions operate within the SDL memory manager:
A memory block obtained or allocated using SDL memory functions must be freed using them. Otherwise you will either get a segmentation fault or memory leaks.
A memory block obtained or allocated using SDL memory functions must be freed using them. Otherwise you will either get a segmentation fault or memory leaks.
But how is the strings pointer returned by backtrace_symbols() bound to SDL memory?
My solution is to have an alternative build that doesn’t use sdl. I have plenty of data structures, parsing code and algorithms that I can test the majority of my code without SDL being involved. I have coverage testing (with and without sdl), alternative builds, asan, etc. This solution might not work in games but it sure does work for my use case
I didn’t actually write or look at the the backtrace code I just wanted to see if the file or glibc malloc was used. I hope that code explains your question on how SDL is overloading malloc. At least that’s how I would assume it does if it does overload malloc