diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2020-02-21 10:28:56 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2020-02-24 01:53:21 +0000 |
commit | 20cf83789df6563828f16fc938ccf05437d366c2 (patch) | |
tree | 2368c5e5006887b6895a935d48000bb8e3ccfdb9 | |
parent | 2bfbdfaf6be5ccebfca38a626d5f36430c98ba13 (diff) | |
download | libinput-20cf83789df6563828f16fc938ccf05437d366c2.tar.gz |
tools: constify the optarg handling of seats
This shuts up scan-build complaining about memory leaks in libinput
debug-events (needs the right combination of --device option and eventually
triggering usage()) and saves us a bunch of unnecessary allocations.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | tools/libinput-debug-events.c | 14 | ||||
-rw-r--r-- | tools/libinput-debug-gui.c | 2 | ||||
-rw-r--r-- | tools/libinput-debug-tablet.c | 2 | ||||
-rw-r--r-- | tools/libinput-list-devices.c | 2 | ||||
-rw-r--r-- | tools/shared.c | 6 | ||||
-rw-r--r-- | tools/shared.h | 2 |
6 files changed, 12 insertions, 16 deletions
diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c index 013fe39d..efdc93f5 100644 --- a/tools/libinput-debug-events.c +++ b/tools/libinput-debug-events.c @@ -967,7 +967,7 @@ main(int argc, char **argv) { struct libinput *li; enum tools_backend backend = BACKEND_NONE; - char *seat_or_devices[60] = {NULL}; + const char *seat_or_devices[60] = {NULL}; size_t ndevices = 0; bool grab = false; bool verbose = false; @@ -1024,7 +1024,7 @@ main(int argc, char **argv) } backend = BACKEND_DEVICE; - seat_or_devices[ndevices++] = safe_strdup(optarg); + seat_or_devices[ndevices++] = optarg; break; case OPT_UDEV: if (backend == BACKEND_DEVICE || @@ -1034,7 +1034,7 @@ main(int argc, char **argv) } backend = BACKEND_UDEV; - seat_or_devices[0] = safe_strdup(optarg); + seat_or_devices[0] = optarg; ndevices = 1; break; case OPT_GRAB: @@ -1064,12 +1064,11 @@ main(int argc, char **argv) usage(); return EXIT_INVALID_USAGE; } - seat_or_devices[ndevices++] = safe_strdup(argv[optind]); + seat_or_devices[ndevices++] = argv[optind]; } while(++optind < argc); } else if (backend == BACKEND_NONE) { backend = BACKEND_UDEV; - seat_or_devices[0] = safe_strdup("seat0"); - ndevices = 1; + seat_or_devices[0] = "seat0"; } memset(&act, 0, sizeof(act)); @@ -1089,9 +1088,6 @@ main(int argc, char **argv) if (!li) return EXIT_FAILURE; - while (ndevices-- > 0) - free(seat_or_devices[ndevices]); - mainloop(li); libinput_unref(li); diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index d68f1ea1..e594ff98 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -1521,7 +1521,7 @@ main(int argc, char **argv) struct tools_options options; struct libinput *li; enum tools_backend backend = BACKEND_NONE; - char *seat_or_device[2] = {"seat0", NULL}; + const char *seat_or_device[2] = {"seat0", NULL}; bool verbose = false; if (!gtk_init_check(&argc, &argv)) diff --git a/tools/libinput-debug-tablet.c b/tools/libinput-debug-tablet.c index b2406d68..642f1e22 100644 --- a/tools/libinput-debug-tablet.c +++ b/tools/libinput-debug-tablet.c @@ -511,7 +511,7 @@ main(int argc, char **argv) struct context ctx; struct libinput *li; enum tools_backend backend = BACKEND_NONE; - char *seat_or_device[2] = {"seat0", NULL}; + const char *seat_or_device[2] = {"seat0", NULL}; struct sigaction act; bool grab = false; diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index 4e0e2c8a..a803e7b7 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -376,7 +376,7 @@ main(int argc, char **argv) struct libinput *li; struct libinput_event *ev; bool grab = false; - char *seat[2] = {"seat0", NULL}; + const char *seat[2] = {"seat0", NULL}; /* This is kept for backwards-compatibility with the old libinput-list-devices */ diff --git a/tools/shared.c b/tools/shared.c index ba813fa4..e80094bc 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -305,11 +305,11 @@ out: } static struct libinput * -tools_open_device(char **paths, bool verbose, bool *grab) +tools_open_device(const char **paths, bool verbose, bool *grab) { struct libinput_device *device; struct libinput *li; - char **p = paths; + const char **p = paths; li = libinput_path_create_context(&interface, grab); if (!li) { @@ -348,7 +348,7 @@ tools_setenv_quirks_dir(void) struct libinput * tools_open_backend(enum tools_backend which, - char **seat_or_device, + const char **seat_or_device, bool verbose, bool *grab) { diff --git a/tools/shared.h b/tools/shared.h index 18662f63..730e1a45 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -116,7 +116,7 @@ int tools_parse_option(int option, const char *optarg, struct tools_options *options); struct libinput* tools_open_backend(enum tools_backend which, - char **seat_or_devices, + const char **seat_or_devices, bool verbose, bool *grab); void tools_device_apply_config(struct libinput_device *device, |