Fixed bug 2502 - Memory leak inside SDL_x11events.c -> X11_DispatchEvent(_THIS)
authorSam Lantinga <slouken@libsdl.org>
Thu, 17 Apr 2014 20:02:11 -0700
changeset 87060c9660fdf9bf
parent 8705 fee2f7e242a1
child 8707 d838991b3fb0
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
     1.1 --- a/src/video/x11/SDL_x11events.c	Thu Apr 17 19:52:15 2014 -0700
     1.2 +++ b/src/video/x11/SDL_x11events.c	Thu Apr 17 20:02:11 2014 -0700
     1.3 @@ -563,19 +563,20 @@
     1.4              long border_top = 0;
     1.5              if (data->xwindow) {
     1.6                  Atom _net_frame_extents = X11_XInternAtom(display, "_NET_FRAME_EXTENTS", 0);
     1.7 -                Atom type = None;
     1.8 +                Atom type;
     1.9                  int format;
    1.10 -                unsigned long nitems = 0, bytes_after;
    1.11 +                unsigned long nitems, bytes_after;
    1.12                  unsigned char *property;
    1.13 -                X11_XGetWindowProperty(display, data->xwindow,
    1.14 -                    _net_frame_extents, 0, 16, 0,
    1.15 -                    XA_CARDINAL, &type, &format,
    1.16 -                    &nitems, &bytes_after, &property);
    1.17 -
    1.18 -                if (type != None && nitems == 4)
    1.19 -                {
    1.20 -                    border_left = ((long*)property)[0];
    1.21 -                    border_top = ((long*)property)[2];
    1.22 +                if (X11_XGetWindowProperty(display, data->xwindow,
    1.23 +                        _net_frame_extents, 0, 16, 0,
    1.24 +                        XA_CARDINAL, &type, &format,
    1.25 +                        &nitems, &bytes_after, &property) == Success) {
    1.26 +                    if (type != None && nitems == 4)
    1.27 +                    {
    1.28 +                        border_left = ((long*)property)[0];
    1.29 +                        border_top = ((long*)property)[2];
    1.30 +                    }
    1.31 +                    X11_XFree(property);
    1.32                  }
    1.33              }
    1.34