richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
661545
From 98234ad6e16e868bd1fa3e4622c43a182fdee75c Mon Sep 17 00:00:00 2001
ea09da
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
ea09da
Date: Sat, 23 Nov 2019 13:37:02 +0100
ea09da
Subject: [PATCH] unit: fix potential use of cgroup_path after free() when
ea09da
 freeing unit
ea09da
661545
Resolves: #1760149
ea09da
---
ea09da
 src/core/cgroup.c | 3 +--
ea09da
 src/core/unit.c   | 2 +-
ea09da
 2 files changed, 2 insertions(+), 3 deletions(-)
ea09da
ea09da
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
661545
index 0ce265dbf4..9af8126957 100644
ea09da
--- a/src/core/cgroup.c
ea09da
+++ b/src/core/cgroup.c
661545
@@ -874,8 +874,7 @@ void unit_destroy_cgroup_if_empty(Unit *u) {
ea09da
 
ea09da
         hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
ea09da
 
ea09da
-        free(u->cgroup_path);
ea09da
-        u->cgroup_path = NULL;
ea09da
+        u->cgroup_path = mfree(u->cgroup_path);
ea09da
         u->cgroup_realized = false;
ea09da
         u->cgroup_realized_mask = 0;
ea09da
 }
ea09da
diff --git a/src/core/unit.c b/src/core/unit.c
661545
index 294c9eb70f..0dc66203a4 100644
ea09da
--- a/src/core/unit.c
ea09da
+++ b/src/core/unit.c
661545
@@ -515,7 +515,7 @@ void unit_free(Unit *u) {
ea09da
 
ea09da
         if (u->cgroup_path) {
ea09da
                 hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
ea09da
-                free(u->cgroup_path);
ea09da
+                u->cgroup_path = mfree(u->cgroup_path);
ea09da
         }
ea09da
 
ea09da
         set_remove(u->manager->failed_units, u);