[PATCH libxi 2/2] Check that allocating a buffer succeeded
Peter Hutterer
peter.hutterer at who-t.net
Tue Oct 25 21:58:32 UTC 2016
On Tue, Oct 25, 2016 at 09:31:19PM +0200, Emilio Pozuelo Monfort wrote:
> Since we are going to write into the buffer, we should make sure the
> allocation didn't fail.
>
> Reported-by: Julien Cristau <jcristau at debian.org>
> Signed-off-by: Emilio Pozuelo Monfort <pochu at debian.org>
both applied, thanks.
1bdeb43..4c5c8d6 master -> master
Cheers,
Peter
> ---
> src/XIQueryDevice.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/XIQueryDevice.c b/src/XIQueryDevice.c
> index e3b0c9f..a877d78 100644
> --- a/src/XIQueryDevice.c
> +++ b/src/XIQueryDevice.c
> @@ -66,17 +66,18 @@ XIQueryDevice(Display *dpy, int deviceid, int *ndevices_return)
> {
> *ndevices_return = reply.num_devices;
> info = Xmalloc((reply.num_devices + 1) * sizeof(XIDeviceInfo));
> + buf = Xmalloc(reply.length * 4);
> }
> else
> {
> *ndevices_return = 0;
> info = NULL;
> + buf = NULL;
> }
>
> - if (!info)
> + if (!info || !buf)
> goto error;
>
> - buf = Xmalloc(reply.length * 4);
> _XRead(dpy, buf, reply.length * 4);
> ptr = buf;
> end = buf + reply.length * 4;
> @@ -135,9 +136,9 @@ error_loop:
> Xfree(info[i].name);
> Xfree(info[i].classes);
> }
> +error:
> Xfree(info);
> Xfree(buf);
> -error:
> UnlockDisplay(dpy);
> error_unlocked:
> SyncHandle();
> --
> 2.9.3
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list