]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: use free_and_replace on global variable
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2021 13:19:36 +0000 (14:19 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2021 16:15:11 +0000 (17:15 +0100)
In normal usage we cannot set it multiple times, but from a fuzzer we
may. Doing it this way is nicer anyway.

src/systemctl/systemctl-compat-shutdown.c
src/systemctl/systemctl.c

index d876c79d33f8621dfc44adb2f9a1f82d41cf9dfa..11154f5f8b261858a409bb62e533432619f0c90e 100644 (file)
@@ -132,9 +132,10 @@ int shutdown_parse_argv(int argc, char *argv[]) {
                 wall = argv + optind + 1;
 
         if (wall) {
-                arg_wall = strv_copy(wall);
-                if (!arg_wall)
+                char **copy = strv_copy(wall);
+                if (!copy)
                         return log_oom();
+                strv_free_and_replace(arg_wall, copy);
         }
 
         optind = argc;
index b82e541d7a6a03d8b78b76648c6b1bcd96a40853..b27da5dad9fb17ca53c08be1525fa7e8bda84b8e 100644 (file)
@@ -1159,8 +1159,8 @@ static int run(int argc, char *argv[]) {
         case ACTION_SUSPEND_THEN_HIBERNATE:
         case ACTION_EMERGENCY:
         case ACTION_DEFAULT:
-                /* systemctl verbs with no equivalent in the legacy commands.  These cannot appear in
-                 * arg_action.  Fall through. */
+                /* systemctl verbs with no equivalent in the legacy commands. These cannot appear in
+                 * arg_action. Fall through. */
 
         case _ACTION_INVALID:
         default: