Memory leak in the render present

Hello Team,

I am observing the memory leak in the below sample code. If I comment out the render present and render clearer then memory leak is not observed.

 homeTexture = IMG_LoadTexture(gRenderer, HomeImgName);
 internetTexture = IMG_LoadTexture(gRenderer, InternetImgName);

int image_count = 10;
SDL_Texture *pLineTexture[image_count];
    for (int iIndex = 0 ; iIndex < image_count; iIndex++)
    {
        snprintf(LineImgName,sizeof(LineImgName), "%s%03d.png",LinePrefixImgName,(iIndex + 1));
        pLineTexture[iIndex] = IMG_LoadTexture(gRenderer, LineImgName);
        if (pLineTexture[iIndex] == NULL)
        {
            for (int iIndex2 = 0 ; iIndex2 < iIndex; iIndex2++)
                SDL_DestroyTexture(pLineTexture[iIndex2]);
            return ERROR;
        }
    }

   do
    {
       lineLoopCount = 50;
        SDL_RenderCopy(gRenderer, homeTexture , NULL, &homeViewport);
        SDL_RenderCopy(gRenderer, internetTexture , NULL, &internetViewport);

        while(lineLoopCount != 0)
        {
            for (index = 0 ; index < image_count; index++)
            {
                SDL_RenderCopy(gRenderer, pLineTexture[index] , NULL, &lineViewport);
                SDL_RenderPresent(gRenderer);
                SDL_Delay(62);
                SDL_RenderClear(gRenderer);
                SDL_Delay(62);
            }
            lineLoopCount--;
        }
        if ((mainLoopCount % 2) == 0)  
        {
            SDL_Delay(1000);
        }
        else
        {
            SDL_Delay(1000);
        }
        mainLoopCount++;
    }while(mainLoopCount < 200);
          
  for (int iIndex = 0 ; iIndex < image_count; iIndex++)
   SDL_DestroyTexture(pLineTexture[iIndex]);

                          

Not pasted full code in the above snippet. Using the libsdl2(SDL2-2.0.4), libsdl2-image(SDL2_image-2.0.1), DirectFB-1.7.7
Could you please help me here.

I don’t know if you have access to it, but if you run your program with valgrind and debug info, maybe it can give you some insight

Also, checking commits in github, seems several where fixed since 2.0.4

i hope it helps

Thanks @JMGK
I have gone through all the Search · memory leak · GitHub related to the memory leak. All the memory leak related patches present in the libsdl2(SDL2-2.0.4).

I have ran with the valgrind tool as well, getting the below information from the valgrind logs

==23887== 
==23887== 100 bytes in 1 blocks are still reachable in loss record 77 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BF2D19: fusion_reactor_new (reactor.c:1641)
==23887==    by 0x4B45659: dfb_wm_core_initialize (wm.c:179)
==23887==    by 0x4AFFE3F: dfb_core_part_initialize (core_parts.c:79)
==23887==    by 0x4AFE157: dfb_core_initialize (core.c:1852)
==23887==    by 0x4AABE45: DirectFB::ICore_Real::Initialize() (CoreDFB_real.cpp:80)
==23887==    by 0x4AA9C6B: CoreDFB_Initialize (CoreDFB.cpp:70)
==23887==    by 0x4AFD189: dfb_core_arena_initialize (core.c:1995)
==23887==    by 0x4AFD493: dfb_core_create (core.c:356)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887== 
==23887== 100 bytes in 1 blocks are still reachable in loss record 78 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BF2D19: fusion_reactor_new (reactor.c:1641)
==23887==    by 0x4BF1A8F: fusion_object_create (object.c:451)
==23887==    by 0x4AFF2AB: dfb_core_create_layer_context (core.c:536)
==23887==    by 0x4B195FF: dfb_layer_create_context (layer_control.c:190)
==23887==    by 0x4B19AB9: dfb_layer_get_primary_context (layer_control.c:311)
==23887==    by 0x4ABAC45: DirectFB::ILayer_Real::GetPrimaryContext(DFBBoolean, __DFB_CoreLayerContext**) (CoreLayer_real.cpp:78)
==23887==    by 0x4AB9E77: CoreLayer_GetPrimaryContext (CoreLayer.cpp:105)
==23887==    by 0x4AA8BE1: InitIDirectFB_Async (idirectfb.c:2022)
==23887==    by 0x4AA9043: IDirectFB_Construct (idirectfb.c:2123)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887== 
==23887== 100 bytes in 1 blocks are still reachable in loss record 79 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BF2D19: fusion_reactor_new (reactor.c:1641)
==23887==    by 0x4BF1A8F: fusion_object_create (object.c:451)
==23887==    by 0x4AFF3F7: dfb_core_create_layer_region (core.c:558)
==23887==    by 0x4B1A115: dfb_layer_region_create (layer_region.c:169)
==23887==    by 0x4B18B53: dfb_layer_context_get_primary_region (layer_context.c:525)
==23887==    by 0x7221253: ???
==23887==    by 0x4B463B7: dfb_wm_init_stack (wm.c:875)
==23887==    by 0x4B42119: dfb_windowstack_create (windowstack.c:246)
==23887==    by 0x4B16519: dfb_layer_context_init (layer_context.c:258)
==23887==    by 0x4B19623: dfb_layer_create_context (layer_control.c:201)
==23887== 
==23887== 100 bytes in 1 blocks are still reachable in loss record 80 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BF2D19: fusion_reactor_new (reactor.c:1641)
==23887==    by 0x4BF1A8F: fusion_object_create (object.c:451)
==23887==    by 0x4AFF68F: dfb_core_create_surface (core.c:602)
==23887==    by 0x4B2C5BF: dfb_surface_create (surface.c:206)
==23887==    by 0x4B17D41: dfb_layer_context_allocate_surface (layer_context.c:1868)
==23887==    by 0x4B188E5: dfb_layer_context_set_configuration (layer_context.c:774)
==23887==    by 0x4B18C31: dfb_layer_context_get_primary_region (layer_context.c:559)
==23887==    by 0x7221253: ???
==23887==    by 0x4B463B7: dfb_wm_init_stack (wm.c:875)
==23887==    by 0x4B42119: dfb_windowstack_create (windowstack.c:246)
==23887== 
==23887== 100 bytes in 1 blocks are still reachable in loss record 81 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BF2D19: fusion_reactor_new (reactor.c:1641)
==23887==    by 0x4BF1A8F: fusion_object_create (object.c:451)
==23887==    by 0x4AFF543: dfb_core_create_palette (core.c:580)
==23887==    by 0x4B1F975: dfb_palette_create (palette.c:125)
==23887==    by 0x4B2C491: dfb_surface_init_palette (surface.c:452)
==23887==    by 0x4B2C9C5: dfb_surface_create (surface.c:323)
==23887==    by 0x4B17D41: dfb_layer_context_allocate_surface (layer_context.c:1868)
==23887==    by 0x4B188E5: dfb_layer_context_set_configuration (layer_context.c:774)
==23887==    by 0x4B18C31: dfb_layer_context_get_primary_region (layer_context.c:559)
==23887==    by 0x7221253: ???
==23887== 
==23887== 108 bytes in 3 blocks are still reachable in loss record 82 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C19A4D: direct_trace_copy_buffer (trace.c:606)
==23887==    by 0x4C10AF1: direct_dbg_calloc (mem.c:206)
==23887==    by 0x4C12645: direct_modules_explore_directory (modules.c:235)
==23887==    by 0x4B3D641: dfb_system_lookup (system.c:266)
==23887==    by 0x4AFD323: dfb_core_create (core.c:289)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887==    by 0x489E651: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 108 bytes in 3 blocks are still reachable in loss record 83 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C19A4D: direct_trace_copy_buffer (trace.c:606)
==23887==    by 0x4C10BFD: direct_dbg_strdup (mem.c:326)
==23887==    by 0x4C1269B: direct_modules_explore_directory (modules.c:245)
==23887==    by 0x4B3D641: dfb_system_lookup (system.c:266)
==23887==    by 0x4AFD323: dfb_core_create (core.c:289)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887==    by 0x489E651: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 126 bytes in 1 blocks are still reachable in loss record 84 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BEFA89: fusion_skirmish_init (lock.c:979)
==23887==    by 0x4BEF45B: fusion_enter (fusion.c:3882)
==23887==    by 0x4AFD421: dfb_core_create (core.c:330)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887==    by 0x489E651: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 132 bytes in 1 blocks are still reachable in loss record 85 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x48A23F7: SDL_UDEV_Init (SDL_udev.c:122)
==23887==    by 0x48A2963: SDL_EVDEV_Init (SDL_evdev.c:464)
==23887==    by 0x489E787: DirectFB_VideoInit (SDL_DirectFB_video.c:286)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 136 bytes in 1 blocks are still reachable in loss record 86 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C0DC7D: direct_hash_insert (hash.c:214)
==23887==    by 0x4C139ED: DirectResultTypeRegister (result.c:98)
==23887==    by 0x4C0BDC1: DirectResult__init (direct_result.c:67)
==23887==    by 0x4C0723B: __D_init_all (init.c:97)
==23887==    by 0x4009E61: call_init.part.0 (dl-init.c:72)
==23887==    by 0x4009F2B: call_init (dl-init.c:30)
==23887==    by 0x4009F2B: _dl_init (dl-init.c:120)
==23887==    by 0x40009C3: ??? (in /lib/ld-2.24.so)
==23887== 
==23887== 136 bytes in 3 blocks are still reachable in loss record 87 of 114
==23887==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==23887==    by 0x4C10BCD: direct_dbg_strdup (mem.c:319)
==23887==    by 0x4C1269B: direct_modules_explore_directory (modules.c:245)
==23887==    by 0x4B3D641: dfb_system_lookup (system.c:266)
==23887==    by 0x4AFD323: dfb_core_create (core.c:289)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887==    by 0x489E651: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 144 bytes in 1 blocks are still reachable in loss record 88 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C1EB47: direct_thread_self (thread.c:216)
==23887==    by 0x4C19915: get_trace_buffer (trace.c:108)
==23887==    by 0x4C19A01: direct_trace_copy_buffer (trace.c:595)
==23887==    by 0x4C10AF1: direct_dbg_calloc (mem.c:206)
==23887==    by 0x4C0F157: direct_log_create (log.c:90)
==23887==    by 0x4C0A79D: direct_config_set (conf.c:415)
==23887==    by 0x4B71C79: dfb_config_set (conf.c:2255)
==23887==    by 0x4B6E66B: dfb_config_read (conf.c:2525)
==23887==    by 0x4B71F05: dfb_config_init (conf.c:2287)
==23887==    by 0x4AA92A9: DirectFBInit (directfb.c:145)
==23887==    by 0x489E5F5: DirectFB_VideoInit (SDL_DirectFB_video.c:228)
==23887== 
==23887== 144 bytes in 9 blocks are still reachable in loss record 89 of 114
==23887==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==23887==    by 0x4945A77: strdup (strdup.c:42)
==23887==    by 0x4C19A5F: direct_trace_copy_buffer (trace.c:611)
==23887==    by 0x4C10BFD: direct_dbg_strdup (mem.c:326)
==23887==    by 0x4BF5FF7: fusion_dbg_shstrdup (shmalloc.c:604)
==23887==    by 0x4AFDA8B: core_arena_add_shared_field (core.c:1276)
==23887==    by 0x4AFFEB5: dfb_core_part_initialize (core_parts.c:98)
==23887==    by 0x4AFE157: dfb_core_initialize (core.c:1852)
==23887==    by 0x4AABE45: DirectFB::ICore_Real::Initialize() (CoreDFB_real.cpp:80)
==23887==    by 0x4AA9C6B: CoreDFB_Initialize (CoreDFB.cpp:70)
==23887==    by 0x4AFD189: dfb_core_arena_initialize (core.c:1995)
==23887==    by 0x4AFD493: dfb_core_create (core.c:356)
==23887== 
==23887== 168 bytes in 1 blocks are still reachable in loss record 91 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4C1B231: direct_thread_create (thread.c:153)
==23887==    by 0x4BEF49B: fusion_enter (fusion.c:3891)
==23887==    by 0x4AFD421: dfb_core_create (core.c:330)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887==    by 0x489E651: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 187 bytes in 1 blocks are still reachable in loss record 92 of 114
==23887==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==23887==    by 0x4D01121: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4D012A5: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4C08D51: Direct::StringBase<char>::operator=(Direct::StringBase<char> const&) (String.h:187)
==23887==    by 0x4C08DAD: Direct::StringTLS::Copy(Direct::StringBase<char> const&) (String.cpp:81)
==23887==    by 0x4C079DD: Direct::StringBase<char>::CopyTLS() (String.cpp:96)
==23887==    by 0x4AD38ED: ToString_CoreSurface (Debug.cpp:516)
==23887==    by 0x4B545AB: IDirectFBSurface_Construct (idirectfbsurface.c:3591)
==23887==    by 0x4B5731F: IDirectFBSurface_Window_Construct (idirectfbsurface_window.c:426)
==23887==    by 0x4B5DE47: IDirectFBWindow_GetSurface (idirectfbwindow.c:358)
==23887==    by 0x489EAF1: DirectFB_CreateWindow (SDL_DirectFB_window.c:132)
==23887==    by 0x489B263: SDL_CreateWindow_REAL (SDL_video.c:1403)
==23887== 
==23887== 187 bytes in 1 blocks are still reachable in loss record 93 of 114
==23887==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==23887==    by 0x4D01121: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4D012A5: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4C08D51: Direct::StringBase<char>::operator=(Direct::StringBase<char> const&) (String.h:187)
==23887==    by 0x4C08DAD: Direct::StringTLS::Copy(Direct::StringBase<char> const&) (String.cpp:81)
==23887==    by 0x4C079DD: Direct::StringBase<char>::CopyTLS() (String.cpp:96)
==23887==    by 0x4AD38ED: ToString_CoreSurface (Debug.cpp:516)
==23887==    by 0x4B545AB: IDirectFBSurface_Construct (idirectfbsurface.c:3591)
==23887==    by 0x4B5731F: IDirectFBSurface_Window_Construct (idirectfbsurface_window.c:426)
==23887==    by 0x4B575DB: IDirectFBSurface_Window_GetSubSurface (idirectfbsurface_window.c:389)
==23887==    by 0x489EB0B: DirectFB_CreateWindow (SDL_DirectFB_window.c:136)
==23887==    by 0x489B263: SDL_CreateWindow_REAL (SDL_video.c:1403)
==23887== 
==23887== 194 bytes in 1 blocks are still reachable in loss record 94 of 114
==23887==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==23887==    by 0x4D01121: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4D012A5: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4C08D51: Direct::StringBase<char>::operator=(Direct::StringBase<char> const&) (String.h:187)
==23887==    by 0x4C08DAD: Direct::StringTLS::Copy(Direct::StringBase<char> const&) (String.cpp:81)
==23887==    by 0x4C079DD: Direct::StringBase<char>::CopyTLS() (String.cpp:96)
==23887==    by 0x4AD37CD: ToString_CoreLayerRegion (Debug.cpp:498)
==23887==    by 0x4B1CED1: dfb_layer_region_flip_update (layer_region.c:499)
==23887==    by 0x721C727: ???
==23887==    by 0x721C9B9: ???
==23887==    by 0x721CC53: ???
==23887==    by 0x4B4A287: dfb_wm_update_stack (wm.c:1643)
==23887== 
==23887== 194 bytes in 1 blocks are still reachable in loss record 95 of 114
==23887==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==23887==    by 0x4D01121: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4D012A5: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4C08D51: Direct::StringBase<char>::operator=(Direct::StringBase<char> const&) (String.h:187)
==23887==    by 0x4C08DAD: Direct::StringTLS::Copy(Direct::StringBase<char> const&) (String.cpp:81)
==23887==    by 0x4C079DD: Direct::StringBase<char>::CopyTLS() (String.cpp:96)
==23887==    by 0x4AD37CD: ToString_CoreLayerRegion (Debug.cpp:498)
==23887==    by 0x4B1CED1: dfb_layer_region_flip_update (layer_region.c:499)
==23887==    by 0x721C727: ???
==23887==    by 0x721C9B9: ???
==23887==    by 0x721ED27: ???
==23887==    by 0x4B4B037: dfb_wm_set_window_config (wm.c:1492)
==23887== 
==23887== 200 bytes in 2 blocks are still reachable in loss record 96 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BF2D19: fusion_reactor_new (reactor.c:1641)
==23887==    by 0x4BF1A8F: fusion_object_create (object.c:451)
==23887==    by 0x4AFF927: dfb_core_create_surface_buffer (core.c:646)
==23887==    by 0x4B3097D: dfb_surface_buffer_create (surface_buffer.c:149)
==23887==    by 0x4B2B5B1: dfb_surface_reconfig (surface.c:864)
==23887==    by 0x4B18079: dfb_layer_context_reallocate_surface (layer_context.c:1983)
==23887==    by 0x4B18863: dfb_layer_context_set_configuration (layer_context.c:769)
==23887==    by 0x4ABDD59: DirectFB::ILayerContext_Real::SetConfiguration(DFBDisplayLayerConfig const*) (CoreLayerContext_real.cpp:91)
==23887==    by 0x4ABB76B: CoreLayerContext_SetConfiguration (CoreLayerContext.cpp:140)
==23887==    by 0x4B58CE5: IDirectFBDisplayLayer_SetConfiguration (idirectfbdisplaylayer.c:625)
==23887== 
==23887== 204 bytes in 3 blocks are still reachable in loss record 97 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4C12645: direct_modules_explore_directory (modules.c:235)
==23887==    by 0x4B3D641: dfb_system_lookup (system.c:266)
==23887==    by 0x4AFD323: dfb_core_create (core.c:289)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887==    by 0x489E651: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 324 bytes in 9 blocks are still reachable in loss record 98 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C19A4D: direct_trace_copy_buffer (trace.c:606)
==23887==    by 0x4C10BFD: direct_dbg_strdup (mem.c:326)
==23887==    by 0x4BF5FF7: fusion_dbg_shstrdup (shmalloc.c:604)
==23887==    by 0x4AFDA8B: core_arena_add_shared_field (core.c:1276)
==23887==    by 0x4AFFEB5: dfb_core_part_initialize (core_parts.c:98)
==23887==    by 0x4AFE157: dfb_core_initialize (core.c:1852)
==23887==    by 0x4AABE45: DirectFB::ICore_Real::Initialize() (CoreDFB_real.cpp:80)
==23887==    by 0x4AA9C6B: CoreDFB_Initialize (CoreDFB.cpp:70)
==23887==    by 0x4AFD189: dfb_core_arena_initialize (core.c:1995)
==23887==    by 0x4AFD493: dfb_core_create (core.c:356)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887== 
==23887== 327 bytes in 9 blocks are still reachable in loss record 99 of 114
==23887==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==23887==    by 0x4C10BCD: direct_dbg_strdup (mem.c:319)
==23887==    by 0x4BF5FF7: fusion_dbg_shstrdup (shmalloc.c:604)
==23887==    by 0x4AFDA8B: core_arena_add_shared_field (core.c:1276)
==23887==    by 0x4AFFEB5: dfb_core_part_initialize (core_parts.c:98)
==23887==    by 0x4AFE157: dfb_core_initialize (core.c:1852)
==23887==    by 0x4AABE45: DirectFB::ICore_Real::Initialize() (CoreDFB_real.cpp:80)
==23887==    by 0x4AA9C6B: CoreDFB_Initialize (CoreDFB.cpp:70)
==23887==    by 0x4AFD189: dfb_core_arena_initialize (core.c:1995)
==23887==    by 0x4AFD493: dfb_core_create (core.c:356)
==23887==    by 0x4AA8D45: IDirectFB_Construct (idirectfb.c:2072)
==23887==    by 0x4AA95CB: DirectFBCreate (directfb.c:249)
==23887== 
==23887== 460 bytes in 1 blocks are still reachable in loss record 100 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x7A2BCE5: ??? (in /lib/libudev.so.1.6.4)
==23887== 
==23887== 480 bytes in 3 blocks are still reachable in loss record 101 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x400AB29: _dl_check_map_versions (dl-version.c:293)
==23887==    by 0x400CA19: dl_open_worker (dl-open.c:275)
==23887==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==23887==    by 0x400C4A1: _dl_open (dl-open.c:649)
==23887==    by 0x4C3CAB9: dlopen_doit (dlopen.c:66)
==23887==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==23887==    by 0x4C3CEEF: _dlerror_run (dlerror.c:163)
==23887==    by 0x4C3CB0F: dlopen@@GLIBC_2.4 (dlopen.c:87)
==23887==    by 0x489B509: SDL_LoadObject_REAL (SDL_sysloadso.c:36)
==23887==    by 0x48A217B: SDL_UDEV_LoadLibrary (SDL_udev.c:259)
==23887==    by 0x48A2407: SDL_UDEV_Init (SDL_udev.c:127)
==23887== 
==23887== 629 bytes in 1 blocks are still reachable in loss record 102 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x40071F5: _dl_new_object (dl-object.c:75)
==23887==    by 0x4004543: _dl_map_object_from_fd (dl-load.c:1006)
==23887==    by 0x4005DFD: _dl_map_object (dl-load.c:2239)
==23887==    by 0x400C837: dl_open_worker (dl-open.c:226)
==23887==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==23887==    by 0x400C4A1: _dl_open (dl-open.c:649)
==23887==    by 0x4C3CAB9: dlopen_doit (dlopen.c:66)
==23887==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==23887==    by 0x4C3CEEF: _dlerror_run (dlerror.c:163)
==23887==    by 0x4C3CB0F: dlopen@@GLIBC_2.4 (dlopen.c:87)
==23887==    by 0x489B509: SDL_LoadObject_REAL (SDL_sysloadso.c:36)
==23887== 
==23887== 776 bytes in 1 blocks are still reachable in loss record 103 of 114
==23887==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==23887==    by 0x487AC53: SDL_GetErrBuf (SDL_thread.c:242)
==23887==    by 0x4842C39: SDL_ClearError_REAL (SDL_error.c:234)
==23887==    by 0x4842325: SDL_InitSubSystem_REAL (SDL.c:116)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 900 bytes in 1 blocks are still reachable in loss record 104 of 114
==23887==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==23887==    by 0x4C08F69: Direct::StringTLS::create(void*, void*) (String.cpp:59)
==23887==    by 0x4C09727: Direct::TLSObject2<Direct::StringTLS, Direct::StringTLS, Direct::StringTLS>::Get(void*) (TLSObject.h:132)
==23887==    by 0x4C079D1: Direct::StringBase<char>::CopyTLS() (String.cpp:93)
==23887==    by 0x4BEC005: ToString_FusionObject (Debug.cpp:72)
==23887==    by 0x4BF0C7B: fusion_object_activate (object.c:581)
==23887==    by 0x4B164FF: dfb_layer_context_init (layer_context.c:251)
==23887==    by 0x4B19623: dfb_layer_create_context (layer_control.c:201)
==23887==    by 0x4B19AB9: dfb_layer_get_primary_context (layer_control.c:311)
==23887==    by 0x4ABAC45: DirectFB::ILayer_Real::GetPrimaryContext(DFBBoolean, __DFB_CoreLayerContext**) (CoreLayer_real.cpp:78)
==23887==    by 0x4AB9E77: CoreLayer_GetPrimaryContext (CoreLayer.cpp:105)
==23887==    by 0x4AA8BE1: InitIDirectFB_Async (idirectfb.c:2022)
==23887== 
==23887== 919 bytes in 3 blocks are still reachable in loss record 105 of 114
==23887==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==23887==    by 0x4D01121: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4D012A5: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4C08D51: Direct::StringBase<char>::operator=(Direct::StringBase<char> const&) (String.h:187)
==23887==    by 0x4C08DAD: Direct::StringTLS::Copy(Direct::StringBase<char> const&) (String.cpp:81)
==23887==    by 0x4C079DD: Direct::StringBase<char>::CopyTLS() (String.cpp:96)
==23887==    by 0x4AD38ED: ToString_CoreSurface (Debug.cpp:516)
==23887==    by 0x4B545AB: IDirectFBSurface_Construct (idirectfbsurface.c:3591)
==23887==    by 0x4AA84E9: IDirectFB_CreateSurface (idirectfb.c:1108)
==23887==    by 0x489D58B: DirectFB_CreateTexture (SDL_DirectFB_render.c:569)
==23887==    by 0x486C11B: SDL_CreateTexture_REAL (SDL_render.c:459)
==23887==    by 0x486C1B1: SDL_CreateTextureFromSurface_REAL (SDL_render.c:536)
==23887== 
==23887== 1,259 bytes in 2 blocks are still reachable in loss record 106 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x40071F5: _dl_new_object (dl-object.c:75)
==23887==    by 0x4004543: _dl_map_object_from_fd (dl-load.c:1006)
==23887==    by 0x4005DFD: _dl_map_object (dl-load.c:2239)
==23887==    by 0x40087AB: openaux (dl-deps.c:63)
==23887==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==23887==    by 0x40089FB: _dl_map_object_deps (dl-deps.c:260)
==23887==    by 0x400C901: dl_open_worker (dl-open.c:269)
==23887==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==23887==    by 0x400C4A1: _dl_open (dl-open.c:649)
==23887==    by 0x4C3CAB9: dlopen_doit (dlopen.c:66)
==23887==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==23887== 
==23887== 1,636 bytes in 1 blocks are still reachable in loss record 107 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C19927: get_trace_buffer (trace.c:112)
==23887==    by 0x4C19A01: direct_trace_copy_buffer (trace.c:595)
==23887==    by 0x4C10AF1: direct_dbg_calloc (mem.c:206)
==23887==    by 0x4C0F157: direct_log_create (log.c:90)
==23887==    by 0x4C0A79D: direct_config_set (conf.c:415)
==23887==    by 0x4B71C79: dfb_config_set (conf.c:2255)
==23887==    by 0x4B6E66B: dfb_config_read (conf.c:2525)
==23887==    by 0x4B71F05: dfb_config_init (conf.c:2287)
==23887==    by 0x4AA92A9: DirectFBInit (directfb.c:145)
==23887==    by 0x489E5F5: DirectFB_VideoInit (SDL_DirectFB_video.c:228)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887== 
==23887== 1,760 bytes in 1 blocks are still reachable in loss record 108 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4B6E1B9: config_allocate (conf.c:434)
==23887==    by 0x4B71EFD: dfb_config_init (conf.c:2284)
==23887==    by 0x4AA92A9: DirectFBInit (directfb.c:145)
==23887==    by 0x489E5F5: DirectFB_VideoInit (SDL_DirectFB_video.c:228)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 1,792 bytes in 1 blocks are still reachable in loss record 109 of 114
==23887==    at 0x4829404: malloc (vg_replace_malloc.c:298)
==23887==    by 0x482BF0B: realloc (vg_replace_malloc.c:785)
==23887==    by 0x4C0EDC7: allocate_interface_desc (interface.c:542)
==23887==    by 0x4C0EEB5: direct_dbg_interface_add (interface.c:585)
==23887==    by 0x4AA95A7: DirectFBCreate (directfb.c:241)
==23887==    by 0x489E651: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 6,201 bytes in 25 blocks are still reachable in loss record 110 of 114
==23887==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==23887==    by 0x4D01121: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4D012A5: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib/libstdc++.so.6.0.22)
==23887==    by 0x4C08D51: Direct::StringBase<char>::operator=(Direct::StringBase<char> const&) (String.h:187)
==23887==    by 0x4C08DAD: Direct::StringTLS::Copy(Direct::StringBase<char> const&) (String.cpp:81)
==23887==    by 0x4C079DD: Direct::StringBase<char>::CopyTLS() (String.cpp:96)
==23887==    by 0x4AD37CD: ToString_CoreLayerRegion (Debug.cpp:498)
==23887==    by 0x4B1CED1: dfb_layer_region_flip_update (layer_region.c:499)
==23887==    by 0x721C727: ???
==23887==    by 0x721C9B9: ???
==23887==    by 0x721CB39: ???
==23887==    by 0x4B4A643: dfb_wm_update_window (wm.c:1685)
==23887== 
==23887== 8,192 bytes in 2 blocks are still reachable in loss record 111 of 114
==23887==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==23887==    by 0x7A34D61: ??? (in /lib/libudev.so.1.6.4)
==23887== 
==23887== 11,169 bytes in 1 blocks are definitely lost in loss record 112 of 114
==23887==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==23887==    by 0x4B6E1DB: config_allocate (conf.c:440)
==23887==    by 0x4B71EFD: dfb_config_init (conf.c:2284)
==23887==    by 0x4AA92A9: DirectFBInit (directfb.c:145)
==23887==    by 0x489E5F5: DirectFB_VideoInit (SDL_DirectFB_video.c:228)
==23887==    by 0x489B005: SDL_VideoInit_REAL (SDL_video.c:513)
==23887==    by 0x48423E3: SDL_InitSubSystem_REAL (SDL.c:173)
==23887==    by 0x8B13: main (memoryLeak.c:94)
==23887== 
==23887== 33,416 bytes in 1 blocks are still reachable in loss record 113 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C0DD0F: direct_hash_insert (hash.c:237)
==23887==    by 0x4C10B19: direct_dbg_calloc (mem.c:210)
==23887==    by 0x4B6B4B7: IDirectFBEventBuffer_WindowReact (idirectfbinputbuffer.c:1046)
==23887==    by 0x4BEF219: event_dispatcher_loop (fusion.c:3565)
==23887==    by 0x4C1E05D: direct_thread_main (thread.c:470)
==23887==    by 0x4D2C56B: start_thread (pthread_create.c:458)
==23887==    by 0x4979301: ??? (clone.S:86)
==23887== 
==23887== 65,596 bytes in 1 blocks are still reachable in loss record 114 of 114
==23887==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==23887==    by 0x4C10AC7: direct_dbg_calloc (mem.c:199)
==23887==    by 0x4BEEB7B: _fusion_event_dispatcher_process (fusion.c:3651)
==23887==    by 0x4BED661: fusion_call_execute (call.c:1651)
==23887==    by 0x4BF43E1: fusion_ref_down (ref.c:1707)
==23887==    by 0x4B30B35: dfb_surface_buffer_unlink (surface_buffer.h:246)
==23887==    by 0x4B30BE9: dfb_surface_buffer_decouple (surface_buffer.c:216)
==23887==    by 0x4B2B5FF: dfb_surface_reconfig (surface.c:845)
==23887==    by 0x4B18079: dfb_layer_context_reallocate_surface (layer_context.c:1983)
==23887==    by 0x4B18863: dfb_layer_context_set_configuration (layer_context.c:769)
==23887==    by 0x4ABDD59: DirectFB::ILayerContext_Real::SetConfiguration(DFBDisplayLayerConfig const*) (CoreLayerContext_real.cpp:91)
==23887==    by 0x4ABB76B: CoreLayerContext_SetConfiguration (CoreLayerContext.cpp:140)
==23887== 
==23887== LEAK SUMMARY:
==23887==    definitely lost: 11,169 bytes in 1 blocks
==23887==    indirectly lost: 0 bytes in 0 blocks
==23887==      possibly lost: 265 bytes in 6 blocks
==23887==    still reachable: 129,677 bytes in 180 blocks
==23887==         suppressed: 0 bytes in 0 blocks

valgrind logs are not giveing much information which is pointing to the SDL library.
any one, could you please provide the suggestions

What kind of “memory leak” is this? If the memory usage is increasing continuously, so the longer the program runs the more memory is consumed, then that certainly shouldn’t be happening. But if it’s a ‘once off’ chunk of memory being consumed but never returned, that’s nothing to worry about.

it’s not once off chunk memory leak. Memory usage(Vmsize, vmrss) is keep on increasing when the above sample application is running which is posted in the above(first message) snippet. In side the do While, i am only doing render copy, and render present. when the do while loop running memory usage is increasing. If we comment out SDL_RenderPresent & SDL_RenderClear from the loop, memory leak is not happening.

you could try run valgrind like this:

  • valgrind --tool=massif ./my_app
  • massif-visualizer massif.out.???

and then you will have a visual map of the possible memory leak.

Ideally, you need compile SDL with debug info, so you get the culprit line inside SDL

i dont know how help more, sadly :frowning:


Hi @JMGK

I have attached the massif.out from that we can see that memory usage is increasing when our application (as the do while loop runs)

I have enabled the debug symbol in the SDL lib and tested, following are the valgrind logs. Not able to upload the full log.

==21118== 112 bytes in 1 blocks are indirectly lost in loss record 36 of 53
==21118==    at 0x4829CE4: operator new(unsigned int) (vg_replace_malloc.c:328)
==21118==    by 0x4AF1D0B: CoreGraphicsStateClient_Init (CoreGraphicsStateClient.cpp:401)
==21118==    by 0x4B227FF: IDirectFBSurface_Construct (idirectfbsurface.c:3668)
==21118==    by 0x4AEB6E5: IDirectFB_CreateSurface (idirectfb.c:1105)
==21118==    by 0x49057A5: DirectFB_CreateDefaultCursor (SDL_DirectFB_mouse.c:104)
==21118==    by 0x4905CEF: DirectFB_InitMouse (SDL_DirectFB_mouse.c:379)
==21118==    by 0x49087F7: DirectFB_VideoInit (SDL_DirectFB_video.c:289)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118== 
==21118== 132 bytes in 1 blocks are still reachable in loss record 37 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x48BC481: SDL_calloc_REAL (SDL_malloc.c:41)
==21118==    by 0x490F4B3: SDL_UDEV_Init (SDL_udev.c:122)
==21118==    by 0x49104E7: SDL_EVDEV_Init (SDL_evdev.c:464)
==21118==    by 0x49087F1: DirectFB_VideoInit (SDL_DirectFB_video.c:286)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== 132 bytes in 3 blocks are still reachable in loss record 38 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x4B857AB: direct_modules_explore_directory (modules.c:235)
==21118==    by 0x4B1AB3B: dfb_system_lookup (system.c:266)
==21118==    by 0x4B04911: dfb_core_create (core.c:289)
==21118==    by 0x4AEC05F: IDirectFB_Construct (idirectfb.c:2069)
==21118==    by 0x4AEC4B5: DirectFBCreate (directfb.c:249)
==21118==    by 0x4908715: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118== 
==21118== 136 bytes in 1 blocks are still reachable in loss record 39 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x4B83315: direct_hash_insert (hash.c:214)
==21118==    by 0x4B85E6D: DirectResultTypeRegister (result.c:98)
==21118==    by 0x4B8092F: __D_init_all (init.c:97)
==21118==    by 0x4009E61: call_init.part.0 (dl-init.c:72)
==21118==    by 0x4009F2B: call_init (dl-init.c:30)
==21118==    by 0x4009F2B: _dl_init (dl-init.c:120)
==21118==    by 0x40009C3: ??? (in /lib/ld-2.24.so)
==21118== 
==21118== 144 bytes in 1 blocks are still reachable in loss record 40 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x4B8B01F: direct_thread_self (thread.c:216)
==21118==    by 0x4B8B06D: direct_thread_self_name (thread.c:237)
==21118==    by 0x4B825E5: direct_initialize (direct.c:177)
==21118==    by 0x4AEC3E9: DirectFBCreate (directfb.c:210)
==21118==    by 0x4908715: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== 144 bytes in 1 blocks are still reachable in loss record 41 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x4B89851: direct_thread_create (thread.c:153)
==21118==    by 0x4B73855: fusion_enter (fusion.c:3891)
==21118==    by 0x4B049F3: dfb_core_create (core.c:330)
==21118==    by 0x4AEC05F: IDirectFB_Construct (idirectfb.c:2069)
==21118==    by 0x4AEC4B5: DirectFBCreate (directfb.c:249)
==21118==    by 0x4908715: DirectFB_VideoInit (SDL_DirectFB_video.c:249)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118== 
==21118== 356 bytes in 1 blocks are indirectly lost in loss record 43 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x4AEB6C1: IDirectFB_CreateSurface (idirectfb.c:1103)
==21118==    by 0x49057A5: DirectFB_CreateDefaultCursor (SDL_DirectFB_mouse.c:104)
==21118==    by 0x4905CEF: DirectFB_InitMouse (SDL_DirectFB_mouse.c:379)
==21118==    by 0x49087F7: DirectFB_VideoInit (SDL_DirectFB_video.c:289)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== 460 bytes in 1 blocks are still reachable in loss record 44 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x7986CE5: ??? (in /lib/libudev.so.1.6.4)
==21118== 
==21118== 480 bytes in 3 blocks are still reachable in loss record 45 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x400AB29: _dl_check_map_versions (dl-version.c:293)
==21118==    by 0x400CA19: dl_open_worker (dl-open.c:275)
==21118==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==21118==    by 0x400C4A1: _dl_open (dl-open.c:649)
==21118==    by 0x4BA3AB9: dlopen_doit (dlopen.c:66)
==21118==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==21118==    by 0x4BA3EEF: _dlerror_run (dlerror.c:163)
==21118==    by 0x4BA3B0F: dlopen@@GLIBC_2.4 (dlopen.c:87)
==21118==    by 0x4902787: SDL_LoadObject_REAL (SDL_sysloadso.c:36)
==21118==    by 0x490F903: SDL_UDEV_LoadLibrary (SDL_udev.c:259)
==21118==    by 0x490F4D3: SDL_UDEV_Init (SDL_udev.c:127)
==21118== 
==21118== 629 bytes in 1 blocks are still reachable in loss record 46 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x40071F5: _dl_new_object (dl-object.c:75)
==21118==    by 0x4004543: _dl_map_object_from_fd (dl-load.c:1006)
==21118==    by 0x4005DFD: _dl_map_object (dl-load.c:2239)
==21118==    by 0x400C837: dl_open_worker (dl-open.c:226)
==21118==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==21118==    by 0x400C4A1: _dl_open (dl-open.c:649)
==21118==    by 0x4BA3AB9: dlopen_doit (dlopen.c:66)
==21118==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==21118==    by 0x4BA3EEF: _dlerror_run (dlerror.c:163)
==21118==    by 0x4BA3B0F: dlopen@@GLIBC_2.4 (dlopen.c:87)
==21118==    by 0x4902787: SDL_LoadObject_REAL (SDL_sysloadso.c:36)
==21118== 
==21118== 776 bytes in 1 blocks are still reachable in loss record 47 of 53
==21118==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==21118==    by 0x48BC465: SDL_malloc_REAL (SDL_malloc.c:36)
==21118==    by 0x48BD3EB: SDL_GetErrBuf (SDL_thread.c:242)
==21118==    by 0x4843779: SDL_ClearError_REAL (SDL_error.c:234)
==21118==    by 0x48426C5: SDL_InitSubSystem_REAL (SDL.c:116)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== 1,259 bytes in 2 blocks are still reachable in loss record 48 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x40071F5: _dl_new_object (dl-object.c:75)
==21118==    by 0x4004543: _dl_map_object_from_fd (dl-load.c:1006)
==21118==    by 0x4005DFD: _dl_map_object (dl-load.c:2239)
==21118==    by 0x40087AB: openaux (dl-deps.c:63)
==21118==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==21118==    by 0x40089FB: _dl_map_object_deps (dl-deps.c:260)
==21118==    by 0x400C901: dl_open_worker (dl-open.c:269)
==21118==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==21118==    by 0x400C4A1: _dl_open (dl-open.c:649)
==21118==    by 0x4BA3AB9: dlopen_doit (dlopen.c:66)
==21118==    by 0x4009D67: _dl_catch_error (dl-error.c:187)
==21118== 
==21118== 1,296 bytes in 1 blocks are indirectly lost in loss record 49 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x4B2261D: IDirectFBSurface_Construct (idirectfbsurface.c:3577)
==21118==    by 0x4AEB6E5: IDirectFB_CreateSurface (idirectfb.c:1105)
==21118==    by 0x49057A5: DirectFB_CreateDefaultCursor (SDL_DirectFB_mouse.c:104)
==21118==    by 0x4905CEF: DirectFB_InitMouse (SDL_DirectFB_mouse.c:379)
==21118==    by 0x49087F7: DirectFB_VideoInit (SDL_DirectFB_video.c:289)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== 1,760 bytes in 1 blocks are still reachable in loss record 50 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x4B2E0C5: config_allocate.part.1 (conf.c:434)
==21118==    by 0x4B316B9: config_allocate (conf.c:2279)
==21118==    by 0x4B316B9: dfb_config_init (conf.c:2284)
==21118==    by 0x4908675: DirectFB_VideoInit (SDL_DirectFB_video.c:228)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== 1,784 (8 direct, 1,776 indirect) bytes in 1 blocks are definitely lost in loss record 51 of 53
==21118==    at 0x482BC54: calloc (vg_replace_malloc.c:711)
==21118==    by 0x48BC481: SDL_calloc_REAL (SDL_malloc.c:41)
==21118==    by 0x4905739: DirectFB_CreateDefaultCursor (SDL_DirectFB_mouse.c:94)
==21118==    by 0x4905CEF: DirectFB_InitMouse (SDL_DirectFB_mouse.c:379)
==21118==    by 0x49087F7: DirectFB_VideoInit (SDL_DirectFB_video.c:289)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== 8,192 bytes in 2 blocks are still reachable in loss record 52 of 53
==21118==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==21118==    by 0x798FD61: ??? (in /lib/libudev.so.1.6.4)
==21118== 
==21118== 11,169 bytes in 1 blocks are definitely lost in loss record 53 of 53
==21118==    at 0x48294FC: malloc (vg_replace_malloc.c:299)
==21118==    by 0x4B2E0F3: config_allocate.part.1 (conf.c:440)
==21118==    by 0x4B316B9: config_allocate (conf.c:2279)
==21118==    by 0x4B316B9: dfb_config_init (conf.c:2284)
==21118==    by 0x4908675: DirectFB_VideoInit (SDL_DirectFB_video.c:228)
==21118==    by 0x48FD76B: SDL_VideoInit_REAL (SDL_video.c:513)
==21118==    by 0x4842769: SDL_InitSubSystem_REAL (SDL.c:173)
==21118==    by 0x4842859: SDL_Init_REAL (SDL.c:244)
==21118==    by 0x4879D85: SDL_Init_DEFAULT (SDL_dynapi_procs.h:89)
==21118==    by 0x487F765: SDL_Init (SDL_dynapi_procs.h:89)
==21118==    by 0x8B13: main (memoryLeak.c:94)
==21118== 
==21118== LEAK SUMMARY:
==21118==    definitely lost: 11,651 bytes in 17 blocks
==21118==    indirectly lost: 1,776 bytes in 4 blocks
==21118==      possibly lost: 144 bytes in 1 blocks
==21118==    still reachable: 14,850 bytes in 54 blocks
==21118==         suppressed: 0 bytes in 0 blocks

It looks like you are using the DirectFB backend, so I’m thinking the leak is probably happening there. I’m not sure how well that is currently supported, back in 2017 there was a discussion over its future.

You’re also using SDL 2.0.4, which is more than six years old, try a recent version - maybe the bug has been fixed