]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core,systemctl: unit_file_find_fragment() provides names with string_hash_ops_free
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 11 Apr 2025 01:28:54 +0000 (10:28 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Apr 2025 00:49:40 +0000 (09:49 +0900)
names are assigned with set_put_strdup(), hence string_hash_ops_free is
used and we can use set_free() rather than set_free_free().

src/core/load-fragment.c
src/systemctl/systemctl-util.c
src/test/test-unit-file.c

index 5c1bc8dd9637c6ac164fc7a1ac7bbe286890d154..e09415e1d326448106e08825d03e6d527aa18552 100644 (file)
@@ -6178,8 +6178,6 @@ static int merge_by_names(Unit *u, Set *names, const char *id) {
 }
 
 int unit_load_fragment(Unit *u) {
-        const char *fragment;
-        _cleanup_set_free_free_ Set *names = NULL;
         int r;
 
         assert(u);
@@ -6201,6 +6199,8 @@ int unit_load_fragment(Unit *u) {
         if (r < 0)
                 return log_error_errno(r, "Failed to rebuild name map: %m");
 
+        const char *fragment;
+        _cleanup_set_free_ Set *names = NULL;
         r = unit_file_find_fragment(u->manager->unit_id_map,
                                     u->manager->unit_name_map,
                                     u->id,
index ecff2453e6255970f2852c1a6b13531e948c6b18..a6771601a1892b48ac6da82a5d0d53f15fcfe933 100644 (file)
@@ -569,15 +569,14 @@ int unit_find_paths(
                                 return log_error_errno(r, "Failed to get DropInPaths: %s", bus_error_message(&error, r));
                 }
         } else {
-                const char *_path;
-                _cleanup_set_free_free_ Set *names = NULL;
-
                 if (!*cached_name_map) {
                         r = unit_file_build_name_map(lp, NULL, cached_id_map, cached_name_map, NULL);
                         if (r < 0)
                                 return r;
                 }
 
+                const char *_path;
+                _cleanup_set_free_ Set *names = NULL;
                 r = unit_file_find_fragment(*cached_id_map, *cached_name_map, unit_name, &_path, &names);
                 if (r < 0)
                         return log_error_errno(r, "Failed to find fragment for '%s': %m", unit_name);
index c7779237b549208f87b2f1f62d534c1253face9e..06aee82bdf6bf8e913f5f1b1ee5e4a9481d1e495 100644 (file)
@@ -63,7 +63,7 @@ TEST(unit_file_build_name_map) {
 
         STRV_FOREACH(id, ids) {
                  const char *fragment, *name;
-                 _cleanup_set_free_free_ Set *names = NULL;
+                 _cleanup_set_free_ Set *names = NULL;
                  log_info("*** %s ***", *id);
                  r = unit_file_find_fragment(unit_ids,
                                              unit_names,