4fbe94
From 4d2145e3edd6ba6ac2e52a232fa5059ecdacaead Mon Sep 17 00:00:00 2001
4fbe94
From: Evgeny Vereshchagin <evvers@ya.ru>
4fbe94
Date: Mon, 24 Dec 2018 00:29:56 +0100
4fbe94
Subject: [PATCH] journal: rely on _cleanup_free_ to free a temporary string
4fbe94
 used in client_context_read_cgroup
4fbe94
4fbe94
Closes https://github.com/systemd/systemd/issues/11253.
4fbe94
4fbe94
(cherry picked from commit ef30f7cac18a810814ada7e6a68a31d48cc9fccd)
4fbe94
4fbe94
Resolves: #1764560
4fbe94
---
4fbe94
 src/journal/journald-context.c | 7 ++-----
4fbe94
 1 file changed, 2 insertions(+), 5 deletions(-)
4fbe94
4fbe94
diff --git a/src/journal/journald-context.c b/src/journal/journald-context.c
4fbe94
index c8e97e16de..3a768094d9 100644
4fbe94
--- a/src/journal/journald-context.c
4fbe94
+++ b/src/journal/journald-context.c
4fbe94
@@ -282,7 +282,7 @@ static int client_context_read_label(
4fbe94
 }
4fbe94
 
4fbe94
 static int client_context_read_cgroup(Server *s, ClientContext *c, const char *unit_id) {
4fbe94
-        char *t = NULL;
4fbe94
+        _cleanup_free_ char *t = NULL;
4fbe94
         int r;
4fbe94
 
4fbe94
         assert(c);
4fbe94
@@ -290,7 +290,6 @@ static int client_context_read_cgroup(Server *s, ClientContext *c, const char *u
4fbe94
         /* Try to acquire the current cgroup path */
4fbe94
         r = cg_pid_get_path_shifted(c->pid, s->cgroup_root, &t);
4fbe94
         if (r < 0 || empty_or_root(t)) {
4fbe94
-
4fbe94
                 /* We use the unit ID passed in as fallback if we have nothing cached yet and cg_pid_get_path_shifted()
4fbe94
                  * failed or process is running in a root cgroup. Zombie processes are automatically migrated to root cgroup
4fbe94
                  * on cgroupsv1 and we want to be able to map log messages from them too. */
4fbe94
@@ -304,10 +303,8 @@ static int client_context_read_cgroup(Server *s, ClientContext *c, const char *u
4fbe94
         }
4fbe94
 
4fbe94
         /* Let's shortcut this if the cgroup path didn't change */
4fbe94
-        if (streq_ptr(c->cgroup, t)) {
4fbe94
-                free(t);
4fbe94
+        if (streq_ptr(c->cgroup, t))
4fbe94
                 return 0;
4fbe94
-        }
4fbe94
 
4fbe94
         free_and_replace(c->cgroup, t);
4fbe94