Fixed resource leak associated with xlib usage, see #33

This commit is contained in:
Jarcode
2018-03-18 22:01:03 -07:00
parent 8024e308d8
commit b446ac99c9
2 changed files with 10 additions and 3 deletions

11
xwin.c
View File

@@ -67,7 +67,7 @@ bool xwin_should_render(struct renderer* rd) {
Atom actual_type;
int actual_format, t;
unsigned long nitems, bytes_after;
unsigned char* data;
unsigned char* data = NULL;
int handler(Display* d, XErrorEvent* e) { return 0; }
@@ -77,7 +77,7 @@ bool xwin_should_render(struct renderer* rd) {
&actual_type, &actual_format, &nitems, &bytes_after, &data)) {
goto close; /* if an error occurs here, the WM probably isn't EWMH compliant */
}
if (!nitems)
goto close;
@@ -85,6 +85,11 @@ bool xwin_should_render(struct renderer* rd) {
prop = XInternAtom(d, "_NET_WM_STATE", true);
if (data) {
XFree(data);
data = NULL;
}
if (Success != XGetWindowProperty(d, active, prop, 0, LONG_MAX, false, AnyPropertyType,
&actual_type, &actual_format, &nitems, &bytes_after, &data)) {
goto close; /* some WMs are a little slow on creating _NET_WM_STATE, so errors may occur here */
@@ -95,6 +100,8 @@ bool xwin_should_render(struct renderer* rd) {
}
}
close:
if (data)
XFree(data);
if (should_close)
XCloseDisplay(d);
return ret;