diff options
author | Pauli Nieminen <ext-pauli.nieminen@nokia.com> | 2010-06-14 10:37:56 +0300 |
---|---|---|
committer | Pauli Nieminen <ext-pauli.nieminen@nokia.com> | 2010-07-13 11:26:13 +0300 |
commit | 3a6839b4a229aa59188025c9b285023110a20aad (patch) | |
tree | e7322bea67fe4a96326ef2d86046b8b475b4df4f /src/XGetDCtl.c | |
parent | 850288fee663c07fbd491859629543f78bbadd3c (diff) |
Use single error path in XGetDeviceControl
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@nokia.com>
Reviewed-by: Julien Cristau <jcristau@debian.org>
Diffstat (limited to 'src/XGetDCtl.c')
-rw-r--r-- | 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(); |