]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: Fix memory leak
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 9 Dec 2021 14:46:13 +0000 (15:46 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 9 Dec 2021 17:13:04 +0000 (18:13 +0100)
src/basic/process-util.c

index 1b96d3ca8543079a5413a3c36872e6f56d6eabd3..c9718521584727bc9601cf5c30f3806e2fbb0bfd 100644 (file)
@@ -221,9 +221,12 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
                         return -ENOMEM;
 
                 /* Drop trailing empty strings. See issue #21186. */
-                STRV_FOREACH_BACKWARDS(p, args)
-                        if (isempty(*p))
-                                *p = mfree(*p);
+                STRV_FOREACH_BACKWARDS(p, args) {
+                        if (!isempty(*p))
+                                break;
+
+                        *p = mfree(*p);
+                }
 
                 ans = quote_command_line(args, shflags);
                 if (!ans)