From 7f1238bd04000f3333e8e2fcb82c9c6e18ee3ffc Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 28 May 2021 19:48:33 +0900 Subject: [PATCH] basic/unit-file: fix use-after-free This fixes a bug introduced by e8630e695232bdfcd16b55f3faafb4329c961104. Fixes CID#1453292. --- src/basic/unit-file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c index fab63b6dcec..f20ae4dbe53 100644 --- a/src/basic/unit-file.c +++ b/src/basic/unit-file.c @@ -303,11 +303,11 @@ int unit_file_build_name_map( return log_oom(); if (paths) { - r = set_consume(paths, filename); + r = set_put(paths, filename); if (r < 0) return log_oom(); - /* We will still use filename below. This is safe because we know the set - * holds a reference. */ + if (r == 0) + _filename_free = filename; /* Make sure we free the filename. */ } else _filename_free = filename; /* Make sure we free the filename. */ -- 2.47.3