[PATCH libXi] Unlock display correctly in event select code

Pauli Nieminen ext-pauli.nieminen at nokia.com
Fri Jun 18 01:48:44 PDT 2010


XISelectEvents and XIGetSelectedEvents were not unlocking display in all
return paths.

Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---

This patch applies on top of my previous libXi patches.

Thanks for Julien Cristau for spotting the bug.

 src/XISelEv.c |   33 +++++++++++++++------------------
 1 files 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;
 }
-- 
1.6.3.3



More information about the xorg-devel mailing list