diff options
author | Pauli Nieminen <ext-pauli.nieminen@nokia.com> | 2010-06-14 10:16:22 +0300 |
---|---|---|
committer | Pauli Nieminen <ext-pauli.nieminen@nokia.com> | 2010-07-13 11:26:13 +0300 |
commit | 9ca839742b49d49e98a17baa40c9662ee76c397f (patch) | |
tree | ebc914cf3afd4e37389d3bc2c50151e1ff768b54 | |
parent | b953bf7b9775e5970776a21ae3f7919592289c92 (diff) |
Use single error path in XQueryDeviceState
This reduces code duplication and fixes possible leak of data. data would
leak if allocation of state fails.
Signed-off-by: Pauli Nieminen <ext-pauli.nieminen@nokia.com>
Reviewed-by: Julien Cristau <jcristau@debian.org>
-rw-r--r-- | src/XQueryDv.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/XQueryDv.c b/src/XQueryDv.c index d9495c2..637d5cf 100644 --- a/src/XQueryDv.c +++ b/src/XQueryDv.c @@ -69,7 +69,7 @@ XQueryDeviceState( xQueryDeviceStateReply rep; XDeviceState *state = NULL; XInputClass *any, *Any; - char *data; + char *data = NULL; XExtDisplayInfo *info = XInput_find_display(dpy); LockDisplay(dpy); @@ -81,20 +81,15 @@ XQueryDeviceState( req->ReqType = X_QueryDeviceState; req->deviceid = dev->device_id; - if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return (XDeviceState *) NULL; - } + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) + goto out; rlen = rep.length << 2; if (rlen > 0) { data = Xmalloc(rlen); if (!data) { _XEatData(dpy, (unsigned long)rlen); - UnlockDisplay(dpy); - SyncHandle(); - return ((XDeviceState *) NULL); + goto out; } _XRead(dpy, data, rlen); @@ -117,11 +112,9 @@ XQueryDeviceState( any = (XInputClass *) ((char *)any + any->length); } state = (XDeviceState *) Xmalloc(size + sizeof(XDeviceState)); - if (!state) { - UnlockDisplay(dpy); - SyncHandle(); - return ((XDeviceState *) NULL); - } + if (!state) + goto out; + state->device_id = dev->device_id; state->num_classes = rep.num_classes; state->data = (XInputClass *) (state + 1); @@ -175,8 +168,9 @@ XQueryDeviceState( } any = (XInputClass *) ((char *)any + any->length); } - Xfree(data); } +out: + Xfree(data); UnlockDisplay(dpy); SyncHandle(); |