From 8daf961d0fe6a1433c8248d984618a7e22ff88b8 Mon Sep 17 00:00:00 2001 From: Pauli Nieminen Date: Fri, 18 Jun 2010 11:32:36 +0300 Subject: Always unlock display correctly XISelectEvents and XIGetSelectedEvents were not unlocking display in all return paths. Reported-by: Julien Cristau Signed-off-by: Pauli Nieminen --- src/XISelEv.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/XISelEv.c b/src/XISelEv.c index 3c1f018..dad890e 100644 --- a/src/XISelEv.c +++ b/src/XISelEv.c @@ -48,11 +48,14 @@ XISelectEvents(Display* dpy, Window win, XIEventMask* masks, int num_masks) xXIEventMask mask; int i; int len = 0; + int r = Success; XExtDisplayInfo *info = XInput_find_display(dpy); LockDisplay(dpy); - if (_XiCheckExtInit(dpy, Dont_Check, info) == -1) - return (NoSuchExtension); + if (_XiCheckExtInit(dpy, Dont_Check, info) == -1) { + r = NoSuchExtension; + goto out; + } GetReq(XISelectEvents, req); req->reqType = info->codes->major_opcode; @@ -85,9 +88,10 @@ XISelectEvents(Display* dpy, Window win, XIEventMask* masks, int num_masks) free(buff); } +out: UnlockDisplay(dpy); SyncHandle(); - return Success; + return r; } @@ -101,13 +105,11 @@ XIGetSelectedEvents(Display* dpy, Window win, int *num_masks_return) xXIGetSelectedEventsReq *req; xXIGetSelectedEventsReply reply; + *num_masks_return = -1; XExtDisplayInfo *info = XInput_find_display(dpy); LockDisplay(dpy); if (_XiCheckExtInit(dpy, Dont_Check, info) == -1) - { - *num_masks_return = -1; - return NULL; - } + goto out; GetReq(XIGetSelectedEvents, req); @@ -116,17 +118,17 @@ XIGetSelectedEvents(Display* dpy, Window win, int *num_masks_return) req->win = win; if (!_XReply(dpy, (xReply *) &reply, 0, xFalse)) - goto error; + goto out; if (reply.num_masks == 0) { *num_masks_return = 0; - return NULL; + goto out; } mask_in = Xmalloc(reply.length * 4); if (!mask_in) - goto error; + goto out; _XRead(dpy, (char*)mask_in, reply.length * 4); @@ -144,7 +146,7 @@ XIGetSelectedEvents(Display* dpy, Window win, int *num_masks_return) mask_out = Xmalloc(len); if (!mask_out) - goto error; + goto out; mi = mask_in; mask = (unsigned char*)&mask_out[reply.num_masks]; @@ -161,16 +163,11 @@ XIGetSelectedEvents(Display* dpy, Window win, int *num_masks_return) *num_masks_return = reply.num_masks; +out: Xfree(mask_in); - return mask_out; - -error: - if (mask_in) - Xfree(mask_in); - *num_masks_return = -1; UnlockDisplay(dpy); SyncHandle(); - return NULL; + return mask_out; } -- cgit v1.2.3