anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0249-journal-rely-on-_cleanup_free_-to-free-a-temporary-s.patch

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