Valgrind / ASAN

I’m taking a look at SDL3 for a production C++ open source app. I’m currently stuck on Valgrind and ASAN complaints. Each leak is coming from SDL3 code.

Valgrind summary

Leak_DefinitelyLost
1,721 (16 direct, 1,705 indirect) bytes in 1 blocks are definitely lost in loss record 126 of 137
16,416 (64 direct, 16,352 indirect) bytes in 1 blocks are definitely lost in loss record 137 of 137
2,048 bytes in 1 blocks are definitely lost in loss record 127 of 137
24 bytes in 1 blocks are definitely lost in loss record 13 of 137
32 bytes in 1 blocks are definitely lost in loss record 16 of 137
40 bytes in 1 blocks are definitely lost in loss record 17 of 137
40 bytes in 1 blocks are definitely lost in loss record 18 of 137
40 bytes in 1 blocks are definitely lost in loss record 19 of 137
7,616 (52 direct, 7,564 indirect) bytes in 1 blocks are definitely lost in loss record 131 of 137
7,851 (64 direct, 7,787 indirect) bytes in 1 blocks are definitely lost in loss record 132 of 137
72 bytes in 1 blocks are definitely lost in loss record 100 of 137
8 bytes in 1 blocks are definitely lost in loss record 4 of 137
8,192 bytes in 1 blocks are definitely lost in loss record 135 of 137
9 bytes in 1 blocks are definitely lost in loss record 5 of 137
  • 0x65D435 X11_InitKeyboard
  • 0x661BF5 GetGlobalContentScale
  • 0x661C24 GetGlobalContentScale
  • 0x65D47F X11_InitKeyboard
  • 0x661C24 GetGlobalContentScale
  • 0x663CAA X11_CreateDevice
  • 0x663CAA X11_CreateDevice
  • 0x65D47F X11_InitKeyboard
  • 0x661C24 GetGlobalContentScale
  • 0x65D47F X11_InitKeyboard
    etc

I’m using SDL_MAIN_USE_CALLBACKS on Linux X11. I haven’t tried Wayland just yet.

Is there something obvious about this pattern? I’m not a SDL veteran.

This is with release-3.2.8.

/usr/bin/valgrind --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no

Thanks!

Clang 18, Ubuntu 20, -DCMAKE_BUILD_TYPE=Debug

Both Valgrind and ASAN report issues on X11.

Could this be related to that?

I read that; not applicable. I think the issue is related to lack of exclusion rules. Will be confirming today

I have Valgrind working with SDL3/X11 with GCC and Clang-18 (no errors) using the following:

/usr/bin/valgrind --tool=memcheck --xml=yes --xml-file=/tmp/valgrind_output_%p --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --suppressions=/usr/share/glib-2.0/valgrind/glib.supp --suppressions=/home/tcna/work/ivi-homescreen/.valgrind.exceptions.supp /home/tcna/work/ivi-homescreen/cmake-build-debug/shell/homescreen -b /home/tcna/workspace-automation/app/samples/material_3_demo/.desktop-homescreen

/usr/share/glib-2.0/valgrind/glib.supp is the system installed file

.valgrind.exceptions.supp contents

    SDL_x11keyboard
    Memcheck:Leak
    match-leak-kinds: definite
    fun:malloc
    ...
    fun:X11_InitKeyboard
    fun:X11_VideoInit
    fun:SDL_*
}

{
    SDL_x11keyboard
    Memcheck:Leak
    match-leak-kinds: definite
    fun:malloc
    ...
    fun:GetGlobalContentScale
    fun:X11_FillXRandRDisplayInfo
    fun:X11_AddXRandRDisplay
    fun:X11_InitModes_XRandR
    fun:X11_InitModes
    fun:X11_VideoInit
    fun:SDL_*
}

{
    SDL_x11mouse
    Memcheck:Leak
    match-leak-kinds: definite
    fun:calloc
    ...
    fun:X11_CreateSystemCursor
    fun:X11_InitMouse
    fun:X11_VideoInit
    fun:SDL_*
}

{
    SDL_x11video
    Memcheck:Leak
    match-leak-kinds: definite
    fun:malloc
    ...
    fun:X11_CreateDevice
    fun:SDL_*
}

{
    SDL_x11modes_00
    Memcheck:Leak
    match-leak-kinds: definite
    fun:malloc
    ...
    fun:GetGlobalContentScale
    fun:X11_FillXRandRDisplayInfo
}

{
    SDL_x11modes_01
    Memcheck:Leak
    match-leak-kinds: definite
    fun:malloc
    ...
    fun:X11_XrmGetStringDatabase
    fun:GetGlobalContentScale
}

{
    SDL_x11modes_01
    Memcheck:Leak
    match-leak-kinds: definite
    fun:malloc
    ...
    fun:GetGlobalContentScale
}

the last one is a bit broad.

I think it would be good to have this checked in as /valgrind/sdl.supp. Thoughts?

By app do you mean something that isn’t a game? I have a ‘headless’ build where I enable asan and not call any SDL functions. It’s been working fine

I’m using SDL3 as a sub-module, top-level ASAN support.

If the backend uses X11 at runtime, and you use Valgrind, then you would hit this. I haven’t tested out the headless path yet; part of the plan.

Moving this combo to SDL3 to enable cross platform:

I’m not seeing any Valgrind issues with Wayland