From 3a6839b4a229aa59188025c9b285023110a20aad Mon Sep 17 00:00:00 2001 From: Pauli Nieminen Date: Mon, 14 Jun 2010 10:37:56 +0300 Subject: 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 Reviewed-by: Julien Cristau --- src/XGetDCtl.c | 23 +++++++++-------------- 1 file 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(); -- cgit v1.2.3