diff options
Diffstat (limited to 'src/events.c')
-rw-r--r-- | src/events.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/events.c b/src/events.c index c66c938..dd998b5 100644 --- a/src/events.c +++ b/src/events.c @@ -441,6 +441,7 @@ key_press (XEvent *ev) static char * execute_remote_command (Window w) { + int status; char *result = NULL; Atom type_ret; int format_ret; @@ -448,28 +449,36 @@ execute_remote_command (Window w) unsigned long bytes_after; unsigned char *req; - if (XGetWindowProperty (dpy, w, rp_command, - 0, 0, False, XA_STRING, - &type_ret, &format_ret, &nitems, &bytes_after, - &req) == Success - && - XGetWindowProperty (dpy, w, rp_command, - 0, (bytes_after / 4) + (bytes_after % 4 ? 1 : 0), - True, XA_STRING, &type_ret, &format_ret, &nitems, - &bytes_after, &req) == Success) + status = XGetWindowProperty (dpy, w, rp_command, + 0, 0, False, XA_STRING, + &type_ret, &format_ret, &nitems, &bytes_after, + &req); + + if (status != Success || req == NULL) { - if (req) - { - PRINT_DEBUG (("command: %s\n", req)); - result = command (0, req); - } - XFree (req); + PRINT_DEBUG (("Couldn't get RP_COMMAND Property\n")); + return NULL; } - else + + /* XGetWindowProperty always allocates one extra byte even if + the property is zero length. */ + XFree (req); + + status = XGetWindowProperty (dpy, w, rp_command, + 0, (bytes_after / 4) + (bytes_after % 4 ? 1 : 0), + True, XA_STRING, &type_ret, &format_ret, &nitems, + &bytes_after, &req); + + if (status != Success || req == NULL) { PRINT_DEBUG (("Couldn't get RP_COMMAND Property\n")); + return NULL; } + PRINT_DEBUG (("command: %s\n", req)); + result = command (0, req); + XFree (req); + return result; } |