Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks on sample/clear.c with opengles2 and software renderer #12500

Open
rustyroot opened this issue Mar 9, 2025 · 1 comment
Open

Comments

@rustyroot
Copy link

compiling with
gcc clear.c -o clear -Wall -Wextra -fsanitize=address `pkg-config --cflags --libs sdl3` -g
the first sample : https://examples.libsdl.org/SDL3/renderer/01-clear/

lead to memory leaks

=================================================================
==30958==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 5323 byte(s) in 255 object(s) allocated from:
    #0 0x7fabe3e7077b in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:439
    #1 0x7fabe307f7be  (<unknown module>)

Direct leak of 1608 byte(s) in 1 object(s) allocated from:
    #0 0x7fabe3eb83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7fabe30b7a7e  (<unknown module>)

Indirect leak of 144 byte(s) in 1 object(s) allocated from:
    #0 0x7fabe3eb83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7fabe300f6dd  (<unknown module>)
    #2 0x30647261632e  (<unknown module>)

Indirect leak of 40 byte(s) in 1 object(s) allocated from:
    #0 0x7fabe3eb83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7fabe30b71e9  (<unknown module>)

SUMMARY: AddressSanitizer: 7115 byte(s) leaked in 258 allocation(s).

So I modified the code to display available renderDriver :

int drivers = SDL_GetNumRenderDrivers();
     for (int d = 0; d < drivers; d++) {
         SDL_Log("Available RenderDriver name: %s", SDL_GetRenderDriver(d));
     }

Available RenderDriver name: opengles2
Available RenderDriver name: vulkan
Available RenderDriver name: gpu
Available RenderDriver name: software

I test all of them by modifying the SDL_APPinit as following :

     if (!(window = SDL_CreateWindow("example memory leak", 640, 480, 0))) {
         SDL_Log("Couldn't create window : %s", SDL_GetError());
         return SDL_APP_FAILURE;
     }

     if (!(renderer = SDL_CreateRenderer( window, "<RenderDriver name>" ))) {
        SDL_Log("Couldn't create renderer : %s", SDL_GetError());
        return SDL_APP_FAILURE;
     }

And I got following results :
gpu : no memory leak
opengles2 : memory leak reported by the sanitizer
vulkan : non memory leak
software : memory leak reported by the sanitizer

I run on a Debian 12, with SDL3.2.8.

@DaneelTrevize
Copy link

DaneelTrevize commented Mar 9, 2025

FWIW, with RenderDriver "direct3d11" and VideoDriver "windows", for the same example code left running obscured by other windows, I see a slow & steady increase in Unresolved allocations according to VS2022's heap profiling & snapshots features.
The stack traces say the allocations come from line 2617 of SDL_render_d3d11.c, the IDXGISwapChain1_Present1() call, and the tip of the trace ends with ntdll.dll!0x7ffc701db5d4(). Most often these are 24, 4104, 4111 or 19295 bytes.

Image
Image

Edit: possibly more interestingly, when I set VS to Release instead of Debug, the debugger/diagnostic tools blames the same Unresolved allocs pattern on line 2623, ID3D11DeviceContext1_DiscardView(data->d3dContext, (ID3D11View *)data->mainRenderTargetView);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants