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>
This commit is contained in:
Peter Hutterer 2020-02-21 10:28:56 +10:00
parent 2bfbdfaf6b
commit 20cf83789d
6 changed files with 12 additions and 16 deletions

View file

@ -967,7 +967,7 @@ main(int argc, char **argv)
{ {
struct libinput *li; struct libinput *li;
enum tools_backend backend = BACKEND_NONE; enum tools_backend backend = BACKEND_NONE;
char *seat_or_devices[60] = {NULL}; const char *seat_or_devices[60] = {NULL};
size_t ndevices = 0; size_t ndevices = 0;
bool grab = false; bool grab = false;
bool verbose = false; bool verbose = false;
@ -1024,7 +1024,7 @@ main(int argc, char **argv)
} }
backend = BACKEND_DEVICE; backend = BACKEND_DEVICE;
seat_or_devices[ndevices++] = safe_strdup(optarg); seat_or_devices[ndevices++] = optarg;
break; break;
case OPT_UDEV: case OPT_UDEV:
if (backend == BACKEND_DEVICE || if (backend == BACKEND_DEVICE ||
@ -1034,7 +1034,7 @@ main(int argc, char **argv)
} }
backend = BACKEND_UDEV; backend = BACKEND_UDEV;
seat_or_devices[0] = safe_strdup(optarg); seat_or_devices[0] = optarg;
ndevices = 1; ndevices = 1;
break; break;
case OPT_GRAB: case OPT_GRAB:
@ -1064,12 +1064,11 @@ main(int argc, char **argv)
usage(); usage();
return EXIT_INVALID_USAGE; return EXIT_INVALID_USAGE;
} }
seat_or_devices[ndevices++] = safe_strdup(argv[optind]); seat_or_devices[ndevices++] = argv[optind];
} while(++optind < argc); } while(++optind < argc);
} else if (backend == BACKEND_NONE) { } else if (backend == BACKEND_NONE) {
backend = BACKEND_UDEV; backend = BACKEND_UDEV;
seat_or_devices[0] = safe_strdup("seat0"); seat_or_devices[0] = "seat0";
ndevices = 1;
} }
memset(&act, 0, sizeof(act)); memset(&act, 0, sizeof(act));
@ -1089,9 +1088,6 @@ main(int argc, char **argv)
if (!li) if (!li)
return EXIT_FAILURE; return EXIT_FAILURE;
while (ndevices-- > 0)
free(seat_or_devices[ndevices]);
mainloop(li); mainloop(li);
libinput_unref(li); libinput_unref(li);

View file

@ -1521,7 +1521,7 @@ main(int argc, char **argv)
struct tools_options options; struct tools_options options;
struct libinput *li; struct libinput *li;
enum tools_backend backend = BACKEND_NONE; enum tools_backend backend = BACKEND_NONE;
char *seat_or_device[2] = {"seat0", NULL}; const char *seat_or_device[2] = {"seat0", NULL};
bool verbose = false; bool verbose = false;
if (!gtk_init_check(&argc, &argv)) if (!gtk_init_check(&argc, &argv))

View file

@ -511,7 +511,7 @@ main(int argc, char **argv)
struct context ctx; struct context ctx;
struct libinput *li; struct libinput *li;
enum tools_backend backend = BACKEND_NONE; enum tools_backend backend = BACKEND_NONE;
char *seat_or_device[2] = {"seat0", NULL}; const char *seat_or_device[2] = {"seat0", NULL};
struct sigaction act; struct sigaction act;
bool grab = false; bool grab = false;

View file

@ -376,7 +376,7 @@ main(int argc, char **argv)
struct libinput *li; struct libinput *li;
struct libinput_event *ev; struct libinput_event *ev;
bool grab = false; bool grab = false;
char *seat[2] = {"seat0", NULL}; const char *seat[2] = {"seat0", NULL};
/* This is kept for backwards-compatibility with the old /* This is kept for backwards-compatibility with the old
libinput-list-devices */ libinput-list-devices */

View file

@ -305,11 +305,11 @@ out:
} }
static struct libinput * 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_device *device;
struct libinput *li; struct libinput *li;
char **p = paths; const char **p = paths;
li = libinput_path_create_context(&interface, grab); li = libinput_path_create_context(&interface, grab);
if (!li) { if (!li) {
@ -348,7 +348,7 @@ tools_setenv_quirks_dir(void)
struct libinput * struct libinput *
tools_open_backend(enum tools_backend which, tools_open_backend(enum tools_backend which,
char **seat_or_device, const char **seat_or_device,
bool verbose, bool verbose,
bool *grab) bool *grab)
{ {

View file

@ -116,7 +116,7 @@ int tools_parse_option(int option,
const char *optarg, const char *optarg,
struct tools_options *options); struct tools_options *options);
struct libinput* tools_open_backend(enum tools_backend which, struct libinput* tools_open_backend(enum tools_backend which,
char **seat_or_devices, const char **seat_or_devices,
bool verbose, bool verbose,
bool *grab); bool *grab);
void tools_device_apply_config(struct libinput_device *device, void tools_device_apply_config(struct libinput_device *device,