This reduces code duplication and fixes possible leak of f. f would leak if
allocation of Feedback fails.

Signed-off-by: Pauli Nieminen <[email protected]>
---
 src/XGetFCtl.c |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/XGetFCtl.c b/src/XGetFCtl.c
index 61df7cf..3d64404 100644
--- a/src/XGetFCtl.c
+++ b/src/XGetFCtl.c
@@ -83,20 +83,16 @@ XGetFeedbackControl(
     req->ReqType = X_GetFeedbackControl;
     req->deviceid = dev->device_id;
 
-    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
-       UnlockDisplay(dpy);
-       SyncHandle();
-       return (XFeedbackState *) NULL;
-    }
+    if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
+       goto out;
+
     if (rep.length > 0) {
        *num_feedbacks = rep.num_feedbacks;
        nbytes = (long)rep.length << 2;
        f = (xFeedbackState *) Xmalloc((unsigned)nbytes);
        if (!f) {
            _XEatData(dpy, (unsigned long)nbytes);
-           UnlockDisplay(dpy);
-           SyncHandle();
-           return (XFeedbackState *) NULL;
+           goto out;
        }
        sav = f;
        _XRead(dpy, (char *)f, nbytes);
@@ -134,11 +130,9 @@ XGetFeedbackControl(
        }
 
        Feedback = (XFeedbackState *) Xmalloc((unsigned)size);
-       if (!Feedback) {
-           UnlockDisplay(dpy);
-           SyncHandle();
-           return (XFeedbackState *) NULL;
-       }
+       if (!Feedback)
+           goto out;
+
        Sav = Feedback;
 
        f = sav;
@@ -253,8 +247,9 @@ XGetFeedbackControl(
            f = (xFeedbackState *) ((char *)f + f->length);
            Feedback = (XFeedbackState *) ((char *)Feedback + Feedback->length);
        }
-       XFree((char *)sav);
     }
+out:
+    XFree((char *)sav);
 
     UnlockDisplay(dpy);
     SyncHandle();
-- 
1.6.3.3

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to