From: Iain Patterson Date: Tue, 17 Mar 2009 15:20:58 +0000 (+0000) Subject: Fix segfaults X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;ds=sidebyside;p=pager.git Fix segfaults Take care of the return code from get_atom_longs(). Free atoms correctly. --- diff --git a/pager.c b/pager.c index e7aa43a..4d99ae3 100644 --- a/pager.c +++ b/pager.c @@ -61,7 +61,7 @@ void setup_pager() { long states = { skip_pager_state }; char buffer[16]; - XChangeProperty(DADisplay, DAWindow, client_state_atom, XA_ATOM, 32, PropModeAppend, &states, 1); + XChangeProperty(DADisplay, DAWindow, client_state_atom, XA_ATOM, 32, PropModeAppend, (unsigned char *) &states, 1); if (desktop >= 0) { if (snprintf(buffer, sizeof(buffer), "Desktop %d", desktop + 1) < 0) return; @@ -72,24 +72,27 @@ void setup_pager() { XStoreName(DADisplay, DAWindow, buffer); } -void get_atom_longs(Atom atom, Atom type, Window window, long **data, unsigned long *num_items) { +int get_atom_longs(Atom atom, Atom type, Window window, long **data, unsigned long *num_items) { Atom actual; int format; unsigned long num_bytes; - XGetWindowProperty(DADisplay, window, atom, 0, 8192, False, type, &actual, &format, num_items, &num_bytes, (unsigned char **) data); + return XGetWindowProperty(DADisplay, window, atom, 0, 8192, False, type, &actual, &format, num_items, &num_bytes, (unsigned char **) data); } -long get_atom_long(Atom atom, Atom type, Window window) { +int get_atom_long(Atom atom, Atom type, Window window, long *ret) { long *data; - long ret = 0; + int status; unsigned long num_items; - get_atom_longs(atom, type, window, &data, &num_items); - if (num_items) ret = data[0]; + *ret = 0; + + status = get_atom_longs(atom, type, window, &data, &num_items); + if (status != Success) return status; + if (num_items) *ret = data[0]; XFree(data); - return ret; + return status; } void check_support() { @@ -137,11 +140,11 @@ void enumerate_clients(client_t ***clients, unsigned long *num_clients, unsigned scale = (double) root_width / (double) dockapp_attr.width; aspect = (double) root_height / (double) dockapp_attr.height; - *active_window = get_atom_long(active_window_atom, XA_WINDOW, dockapp_attr.root); - *active_desktop = get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay)); + if (get_atom_long(active_window_atom, XA_WINDOW, dockapp_attr.root, (long *) active_window) != Success) *active_window = 0; + if (get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay), (long *) active_desktop) != Success) *active_desktop = 0; if (client_list_supported) { - get_atom_longs(client_list_atom, XA_WINDOW, dockapp_attr.root, &data, num_clients); + if (get_atom_longs(client_list_atom, XA_WINDOW, dockapp_attr.root, &data, num_clients) != Success) XFree(data); } else { XQueryTree(DADisplay, dockapp_attr.root, &qroot, &qparent, &wins, (unsigned int *) num_clients); @@ -165,7 +168,7 @@ void enumerate_clients(client_t ***clients, unsigned long *num_clients, unsigned else client = XmuClientWindow(DADisplay, wins[i]); /* Check the window is on our desktop (or all desktops). */ - client_desktop = get_atom_long(client_desktop_atom, XA_CARDINAL, client); + if (get_atom_long(client_desktop_atom, XA_CARDINAL, client, &client_desktop) != Success) continue; if (desktop > -1) { if (client_desktop != desktop && client_desktop != -1) continue; } @@ -179,12 +182,15 @@ void enumerate_clients(client_t ***clients, unsigned long *num_clients, unsigned /* Make sure it isn't hidden or shaded. */ draw = 1; - get_atom_longs(client_state_atom, XA_ATOM, client, &states, &num_states); - for (j = 0; j < num_states; j++) { - if (states[j] == shaded_state) height = 3.0 * scale; - if (states[j] == skip_pager_state) draw = 0; - if (states[j] == hidden_state) draw = 0; + if (get_atom_longs(client_state_atom, XA_ATOM, client, &states, &num_states) == Success) { + for (j = 0; j < num_states; j++) { + if (states[j] == shaded_state) height = 3.0 * scale; + if (states[j] == skip_pager_state) draw = 0; + if (states[j] == hidden_state) draw = 0; + } + XFree(states); } + else continue; if (! draw) continue; (*clients)[i]->window = client; @@ -440,9 +446,9 @@ int main(int argc, char **argv) { check_support(); - num_desktops = get_atom_long(num_desktops_atom, XA_CARDINAL, DefaultRootWindow(DADisplay)); + if (get_atom_long(num_desktops_atom, XA_CARDINAL, DefaultRootWindow(DADisplay), &num_desktops) != Success) num_desktops = 1; if (desktop == 0) { - desktop = get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay)); + if (get_atom_long(current_desktop_atom, XA_CARDINAL, DefaultRootWindow(DADisplay), (long *) &desktop) != Success) desktop = 0; } else if (desktop < 0) desktop = -1; else if (desktop-- > num_desktops) {