[PATCH 5/5] libXi: Use single error path in XGetDeviceControl
Julien Cristau
jcristau at debian.org
Thu Jun 17 09:05:26 PDT 2010
On Mon, Jun 14, 2010 at 11:47:35 +0300, Pauli Nieminen wrote:
> 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();
Reviewed-by: Julien Cristau <jcristau at debian.org>
Cheers,
Julien
More information about the xorg-devel
mailing list