[PATCH 4/5] libXi: Use single error path in XGetFeedbackControl
Pauli Nieminen
ext-pauli.nieminen at nokia.com
Mon Jun 14 01:47:34 PDT 2010
This reduces code duplication and fixes possible leak of f. f would leak if
allocation of Feedback fails.
Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---
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
More information about the xorg-devel
mailing list