[PATCH 5/5] libXi: Use single error path in XGetDeviceControl
Pauli Nieminen
ext-pauli.nieminen at nokia.com
Mon Jun 14 01:47:35 PDT 2010
This reduces code duplication and fixes possible leak of d. d would leak if
allocation of Device fails.
Signed-off-by: Pauli Nieminen <ext-pauli.nieminen at nokia.com>
---
src/XGetDCtl.c | 23 +++++++++--------------
1 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/src/XGetDCtl.c b/src/XGetDCtl.c
index 8f76a51..729b0a0 100644
--- a/src/XGetDCtl.c
+++ b/src/XGetDCtl.c
@@ -84,19 +84,15 @@ XGetDeviceControl(
req->deviceid = dev->device_id;
req->control = control;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (XDeviceControl *) NULL;
- }
+ if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
+ goto out;
+
if (rep.length > 0) {
nbytes = (long)rep.length << 2;
d = (xDeviceState *) Xmalloc((unsigned)nbytes);
if (!d) {
_XEatData(dpy, (unsigned long)nbytes);
- UnlockDisplay(dpy);
- SyncHandle();
- return (XDeviceControl *) NULL;
+ goto out;
}
sav = d;
_XRead(dpy, (char *)d, nbytes);
@@ -138,11 +134,9 @@ XGetDeviceControl(
}
Device = (XDeviceControl *) Xmalloc((unsigned)size);
- if (!Device) {
- UnlockDisplay(dpy);
- SyncHandle();
- return (XDeviceControl *) NULL;
- }
+ if (!Device)
+ goto out;
+
Sav = Device;
d = sav;
@@ -228,8 +222,9 @@ XGetDeviceControl(
default:
break;
}
- XFree(sav);
}
+out:
+ XFree(sav);
UnlockDisplay(dpy);
SyncHandle();
--
1.6.3.3
More information about the xorg-devel
mailing list