From 3ea8f02027b18cf06774c8f26a719e321e9a78f2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 12 Sep 2018 14:49:21 +1000 Subject: [PATCH xinput] property: plug a memory leak Not that it matters since we'll exit after this call anyway, but coverity is unhappy and that makes us all unhappy, doesn't it? Signed-off-by: Peter Hutterer --- src/property.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/property.c b/src/property.c index e4a46f8..071f80f 100644 --- a/src/property.c +++ b/src/property.c @@ -610,19 +610,20 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int argc, char **argv, char unsigned char *c; int16_t *s; int32_t *l; - } data; + } data = { NULL }; + int rc = EXIT_FAILURE; if (argc < 3) { fprintf(stderr, "Usage: xinput %s %s\n", n, desc); - return EXIT_FAILURE; + goto out; } info = xi2_find_device_info(dpy, argv[0]); if (!info) { fprintf(stderr, "unable to find device %s\n", argv[0]); - return EXIT_FAILURE; + goto out; } name = argv[1]; @@ -631,7 +632,7 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int argc, char **argv, char if (prop == None) { fprintf(stderr, "invalid property '%s'\n", name); - return EXIT_FAILURE; + goto out; } float_atom = XInternAtom(dpy, "FLOAT", False); @@ -643,7 +644,7 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int argc, char **argv, char &bytes_after, &data.c) != Success) { fprintf(stderr, "failed to get property type and format for '%s'\n", name); - return EXIT_FAILURE; + goto out; } else { if (type == None) type = old_type; @@ -657,7 +658,7 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int argc, char **argv, char if (type == None) { fprintf(stderr, "property '%s' doesn't exist, you need to specify " "its type and format\n", name); - return EXIT_FAILURE; + goto out; } data.c = calloc(nelements, sizeof(int32_t)); @@ -678,36 +679,38 @@ do_set_prop_xi2(Display *dpy, Atom type, int format, int argc, char **argv, char break; default: fprintf(stderr, "unexpected size for property %s", name); - return EXIT_FAILURE; + goto out; } } else if (type == float_atom) { if (format != 32) { fprintf(stderr, "unexpected format %d for property '%s'\n", format, name); - return EXIT_FAILURE; + goto out; } *(float *)(data.l + i) = strtod(argv[2 + i], &endptr); if (endptr == argv[2 + i]) { fprintf(stderr, "argument %s could not be parsed\n", argv[2 + i]); - return EXIT_FAILURE; + goto out; } } else if (type == XA_ATOM) { if (format != 32) { fprintf(stderr, "unexpected format %d for property '%s'\n", format, name); - return EXIT_FAILURE; + goto out; } data.l[i] = parse_atom(dpy, argv[2 + i]); } else { fprintf(stderr, "unexpected type for property '%s'\n", name); - return EXIT_FAILURE; + goto out; } } XIChangeProperty(dpy, info->deviceid, prop, type, format, PropModeReplace, data.c, nelements); + rc = EXIT_SUCCESS; +out: free(data.c); - return EXIT_SUCCESS; + return rc; } #endif -- 2.17.1