tools: constify the optarg handling of seats
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 21 Feb 2020 00:28:56 +0000 (10:28 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 24 Feb 2020 01:53:21 +0000 (01:53 +0000)
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>
tools/libinput-debug-events.c
tools/libinput-debug-gui.c
tools/libinput-debug-tablet.c
tools/libinput-list-devices.c
tools/shared.c
tools/shared.h

index 013fe39dcfcdeb4ad7e5327f216e5a24bbfbdf92..efdc93f513dc3bf98a42a82a0fd79085d4ad4c73 100644 (file)
@@ -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);
index d68f1ea147ca7910a95ee767323e97e67db92b8f..e594ff9879ebca68f5f7366c72eb519bef0a12a1 100644 (file)
@@ -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))
index b2406d6804362f0f608ad1e9caf99a747482203d..642f1e227c2e78b9255f94d03d39121dbeeb1f12 100644 (file)
@@ -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;
 
index 4e0e2c8a631623e18825312968318add7192641d..a803e7b70a4502c5996bf8c1d236802b8e8ac11f 100644 (file)
@@ -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 */
index ba813fa44deba5bc644b1a14a3a0059f4e39b3b6..e80094bc7a23b69309cc813bb36b3e336175df97 100644 (file)
@@ -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)
 {
index 18662f6375d70278334ede94ee783f23a2978c45..730e1a45690d269418a85d480728cedcbfe6d82e 100644 (file)
@@ -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,