daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Blob Blame History Raw
From ca52de3b56d5e70232bee29314cd84f5596c1e7f Mon Sep 17 00:00:00 2001
From: Daan De Meyer <daan.j.demeyer@gmail.com>
Date: Thu, 9 Dec 2021 15:46:13 +0100
Subject: [PATCH] process-util: Fix memory leak

---
 src/basic/process-util.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 1b96d3ca8543..c97185215847 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -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)