We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2086

Summary: valgrind memory not released ..
Product: SDL Reporter: Sylvain <sylvain.becker>
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: 0.0.0.0, icculus, jightuse, jones
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: example

Description Sylvain 2013-09-04 20:24:14 UTC
Hi,

I have a few memory-not-released warnings from Valgrind with --leak-check=full.
Don't know if it's related to SDL of ubuntu internals.

==6196== 18 bytes in 2 blocks are definitely lost in loss record 12 of 153
==6196==    at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6196==    by 0x60438D1: strdup (strdup.c:42)
==6196==    by 0x72CC315: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72CD254: _XimSetICValueData (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72C887D: _XimLocalCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72AECE2: XCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x4EEF6CA: SetupWindowData (SDL_x11window.c:240)
==6196==    by 0x4EEFB29: X11_CreateWindow (SDL_x11window.c:547)
==6196==    by 0x4ED7DD7: SDL_CreateWindow (SDL_video.c:1250)
==6196==    by 0x4ED7BDF: SDL_VideoInit (SDL_video.c:171)
==6196==    by 0x4E45A1E: SDL_InitSubSystem (SDL.c:166)
...

==6196== 
==6196== 18 bytes in 2 blocks are definitely lost in loss record 13 of 153
==6196==    at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6196==    by 0x60438D1: strdup (strdup.c:42)
==6196==    by 0x72CC315: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72CD254: _XimSetICValueData (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72C887D: _XimLocalCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72AECE2: XCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x4EEF6CA: SetupWindowData (SDL_x11window.c:240)
==6196==    by 0x4EEFB29: X11_CreateWindow (SDL_x11window.c:547)
==6196==    by 0x4ED7DD7: SDL_CreateWindow (SDL_video.c:1250)
...

==6196== 
==6196== 18 bytes in 2 blocks are definitely lost in loss record 14 of 153
==6196==    at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6196==    by 0x60438D1: strdup (strdup.c:42)
==6196==    by 0x72CC315: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72CD254: _XimSetICValueData (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72C887D: _XimLocalCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x72AECE2: XCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6196==    by 0x4EEF6CA: SetupWindowData (SDL_x11window.c:240)
==6196==    by 0x4EEFB29: X11_CreateWindow (SDL_x11window.c:547)
==6196==    by 0x4ED6614: SDL_RecreateWindow (SDL_video.c:1345)
==6196==    by 0x4E7F837: GL_CreateRenderer (SDL_render_gl.c:381)
==6196==    by 0x4E798C0: SDL_CreateRenderer (SDL_render.c:244)
...


Thanks,

Sylvain
Comment 1 Sam Lantinga 2013-09-05 01:52:04 UTC
Can you post the code that generated those warnings?  It's possible that it's a legitimate leak in the X11 libraries.
Comment 2 Sylvain 2013-09-05 06:36:00 UTC
Created attachment 1321 [details]
example
Comment 3 Sylvain 2013-09-05 06:36:54 UTC
Here's a sample program with only init/window/renderer.
Comment 4 Ryan C. Gordon 2013-10-21 02:46:05 UTC
This is a bug in Xlib, which has existed since forever.

We should go send x.org a patch, so this stops coming up in SDL. If you google for _XimSetICValueData, all the results are Valgrind reports about SDL.  :(

--ryan.
Comment 5 Ryan C. Gordon 2014-02-23 01:28:55 UTC
*** Bug 2305 has been marked as a duplicate of this bug. ***
Comment 6 Sylvain 2014-04-14 15:49:10 UTC
Someone provided a patch for this, recently on the mailing list : 
-----

Hi,

it is possible to skip the bug in libX11 by using the defaults for
XNResourceName and XNResourceClass in `XCreateIC' (the table for the
"Input Context Values" [1] in libX11-doc shows that a default is
provided if it is not set).

diff -ur SDL2-2.0.3~/src/video/x11/SDL_x11window.c SDL2-2.0.3/src/video/x11/SDL_x11window.c
--- SDL2-2.0.3~/src/video/x11/SDL_x11window.c   2014-04-04 17:09:40.764307181 +0200
+++ SDL2-2.0.3/src/video/x11/SDL_x11window.c    2014-04-04 17:10:23.887765046 +0200
@@ -239,8 +239,7 @@
         data->ic =
             X11_XCreateIC(videodata->im, XNClientWindow, w, XNFocusWindow, w,
                        XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
-                       XNResourceName, videodata->classname, XNResourceClass,
-                       videodata->classname, NULL);
+                       NULL);
     }
 #endif
     data->created = created;


Tito Latini

[1] http://www.x.org/releases/X11R7.7-RC1/doc/libX11/libX11/libX11.html#Input_Context_Values
Comment 7 Sylvain 2014-04-14 17:11:50 UTC
It seems to work, but there is also another memory leak in : 

==17670==    at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17670==    by 0x72BE4F0: XGetWindowProperty (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==17670==    by 0x4F0BFA7: X11_DispatchEvent (SDL_x11events.c:570)
==17670==    by 0x4F0CA77: X11_PumpEvents (SDL_x11events.c:1013)
==17670==    by 0x4E7F5E8: SDL_PollEvent_REAL (SDL_events.c:402)

Missing a: 
           X11_XFree(property);
Comment 9 Sam Lantinga 2014-04-18 03:07:51 UTC
Marking this bug fixed.
Comment 10 Sam Lantinga 2014-04-18 03:55:07 UTC
*** Bug 2493 has been marked as a duplicate of this bug. ***
Comment 11 Sylvain 2014-04-21 22:14:32 UTC
Hi, I reopen it, because with newest ubuntu 14.04, this one appears :

==20917==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20917==    by 0x9301A11: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==20917==    by 0x92DA600: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==20917==    by 0x92D6E7A: ??? (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==20917==    by 0x92D760F: glXChooseVisual (in /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0)
==20917==    by 0x4F146D7: X11_GL_LoadLibrary (SDL_x11opengl.c:525)
==20917==    by 0x4F065DC: SDL_CreateWindow_REAL (SDL_video.c:2415)
==20917==    by 0x4F0637F: SDL_VideoInit_REAL (SDL_video.c:193)
==20917==    by 0x4E4992E: SDL_Init_REAL (SDL.c:173)
Comment 12 Sam Lantinga 2014-04-26 19:42:47 UTC
Please open new bugs for new memory leaks.

Thanks!