[PATCH] Fix a memory leak in X11_InitKeyboard

Tapani Pälli <[email protected]>
Newsgroups gmane.comp.lib.sdl
Message-ID <[email protected]>
Patch uses XkbFreeKeyboard to free the memory returned by XkbGetMap.
Earlier implementation called XkbFreeClientMap which frees all the maps
but not data->xkb structure itself, XkbFreeKeyboard will free maps and
the structure.

--- 8< ---
==23869== 72 bytes in 1 blocks are definitely lost in loss record 92 of 133
==23869==    at 0x4C2DA60: calloc (vg_replace_malloc.c:711)
==23869==    by 0x8D10530: XkbGetMap (in /usr/lib64/libX11.so.6.3.0)
==23869==    by 0x4F1DC5D: X11_InitKeyboard (SDL_x11keyboard.c:279)

Signed-off-by: Tapani Pälli <[email protected]>
---
 src/video/x11/SDL_x11keyboard.c | 2 +-
 src/video/x11/SDL_x11sym.h      | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c
index acc15d7..1e276ef 100644
--- a/src/video/x11/SDL_x11keyboard.c
+++ b/src/video/x11/SDL_x11keyboard.c
@@ -484,7 +484,7 @@ X11_QuitKeyboard(_THIS)
 
 #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
     if (data->xkb) {
-        X11_XkbFreeClientMap(data->xkb, 0, True);
+        X11_XkbFreeKeyboard(data->xkb, 0, True);
         data->xkb = NULL;
     }
 #endif
diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h
index 371f6a4..758dd2c 100644
--- a/src/video/x11/SDL_x11sym.h
+++ b/src/video/x11/SDL_x11sym.h
@@ -179,6 +179,7 @@ SDL_X11_SYM(Status,XkbGetState,(Display* a,unsigned int b,XkbStatePtr c),(a,b,c)
 SDL_X11_SYM(Status,XkbGetUpdatedMap,(Display* a,unsigned int b,XkbDescPtr c),(a,b,c),return)
 SDL_X11_SYM(XkbDescPtr,XkbGetMap,(Display* a,unsigned int b,unsigned int c),(a,b,c),return)
 SDL_X11_SYM(void,XkbFreeClientMap,(XkbDescPtr a,unsigned int b, Bool c),(a,b,c),)
+SDL_X11_SYM(void,XkbFreeKeyboard,(XkbDescPtr a,unsigned int b, Bool c),(a,b,c),)
 SDL_X11_SYM(BOOL,XkbSetDetectableAutoRepeat,(Display* a, BOOL b, BOOL* c),(a,b,c),return)
 #endif
 
-- 
2.7.4

_______________________________________________
SDL mailing list
[email protected]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.