From f6953cf4c2facd8897e0c53e969c1d0e8020bd0d Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 17 Apr 2014 20:02:11 -0700 Subject: [PATCH] Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS) bojko_1000 Code @566: if (data->xwindow) { Atom _net_frame_extents = X11_XInternAtom(display, "_NET_FRAME_EXTENTS", 0); Atom type = None; int format; unsigned long nitems = 0, bytes_after; unsigned char *property; X11_XGetWindowProperty(display, data->xwindow, _net_frame_extents, 0, 16, 0, XA_CARDINAL, &type, &format, &nitems, &bytes_after, &property); if (type != None && nitems == 4) { border_left = ((long*)property)[0]; border_right = ((long*)property)[1]; border_top = ((long*)property)[2]; border_bottom = ((long*)property)[3]; } } Code after _the fix_: if (data->xwindow) { Atom _net_frame_extents = X11_XInternAtom(display, "_NET_FRAME_EXTENTS", 0); Atom type = None; int format; unsigned long nitems = 0, bytes_after; unsigned char *property; X11_XGetWindowProperty(display, data->xwindow, _net_frame_extents, 0, 16, 0, XA_CARDINAL, &type, &format, &nitems, &bytes_after, &property); if (type != None && nitems == 4) { border_left = ((long*)property)[0]; border_right = ((long*)property)[1]; border_top = ((long*)property)[2]; border_bottom = ((long*)property)[3]; } X11_XFree(property); } I have found that leak with valgrind. --- src/video/x11/SDL_x11events.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index e6fe9c40f..50e73946d 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -563,19 +563,20 @@ X11_DispatchEvent(_THIS) long border_top = 0; if (data->xwindow) { Atom _net_frame_extents = X11_XInternAtom(display, "_NET_FRAME_EXTENTS", 0); - Atom type = None; + Atom type; int format; - unsigned long nitems = 0, bytes_after; + unsigned long nitems, bytes_after; unsigned char *property; - X11_XGetWindowProperty(display, data->xwindow, - _net_frame_extents, 0, 16, 0, - XA_CARDINAL, &type, &format, - &nitems, &bytes_after, &property); - - if (type != None && nitems == 4) - { - border_left = ((long*)property)[0]; - border_top = ((long*)property)[2]; + if (X11_XGetWindowProperty(display, data->xwindow, + _net_frame_extents, 0, 16, 0, + XA_CARDINAL, &type, &format, + &nitems, &bytes_after, &property) == Success) { + if (type != None && nitems == 4) + { + border_left = ((long*)property)[0]; + border_top = ((long*)property)[2]; + } + X11_XFree(property); } }