9e3166
From ca52de3b56d5e70232bee29314cd84f5596c1e7f Mon Sep 17 00:00:00 2001
9e3166
From: Daan De Meyer <daan.j.demeyer@gmail.com>
9e3166
Date: Thu, 9 Dec 2021 15:46:13 +0100
9e3166
Subject: [PATCH] process-util: Fix memory leak
9e3166
9e3166
---
9e3166
 src/basic/process-util.c | 9 ++++++---
9e3166
 1 file changed, 6 insertions(+), 3 deletions(-)
9e3166
9e3166
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
9e3166
index 1b96d3ca8543..c97185215847 100644
9e3166
--- a/src/basic/process-util.c
9e3166
+++ b/src/basic/process-util.c
9e3166
@@ -221,9 +221,12 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
9e3166
                         return -ENOMEM;
9e3166
 
9e3166
                 /* Drop trailing empty strings. See issue #21186. */
9e3166
-                STRV_FOREACH_BACKWARDS(p, args)
9e3166
-                        if (isempty(*p))
9e3166
-                                *p = mfree(*p);
9e3166
+                STRV_FOREACH_BACKWARDS(p, args) {
9e3166
+                        if (!isempty(*p))
9e3166
+                                break;
9e3166
+
9e3166
+                        *p = mfree(*p);
9e3166
+                }
9e3166
 
9e3166
                 ans = quote_command_line(args, shflags);
9e3166
                 if (!ans)