]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dbus-manager: use _cleanup_ for UnitFileList hash
authorDavid Tardon <dtardon@redhat.com>
Tue, 28 Mar 2023 07:32:40 +0000 (09:32 +0200)
committerDavid Tardon <dtardon@redhat.com>
Tue, 28 Mar 2023 12:19:30 +0000 (14:19 +0200)
src/core/dbus-manager.c

index c88ef93443c97c263873e732bba9a433506757fc..16eefce128bd0269c1430998bd29e0d328bb63f4 100644 (file)
@@ -2094,7 +2094,7 @@ static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata,
         _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         Manager *m = ASSERT_PTR(userdata);
         UnitFileList *item;
-        Hashmap *h;
+        _cleanup_(hashmap_freep) Hashmap *h = NULL;
         int r;
 
         assert(message);
@@ -2109,36 +2109,30 @@ static int list_unit_files_by_patterns(sd_bus_message *message, void *userdata,
         if (r < 0)
                 return r;
 
-        h = hashmap_new(&string_hash_ops);
+        h = hashmap_new(&unit_file_list_hash_ops_free);
         if (!h)
                 return -ENOMEM;
 
         r = unit_file_get_list(m->runtime_scope, NULL, h, states, patterns);
         if (r < 0)
-                goto fail;
+                return r;
 
         r = sd_bus_message_open_container(reply, 'a', "(ss)");
         if (r < 0)
-                goto fail;
+                return r;
 
         HASHMAP_FOREACH(item, h) {
 
                 r = sd_bus_message_append(reply, "(ss)", item->path, unit_file_state_to_string(item->state));
                 if (r < 0)
-                        goto fail;
+                        return r;
         }
 
-        unit_file_list_free(h);
-
         r = sd_bus_message_close_container(reply);
         if (r < 0)
                 return r;
 
         return sd_bus_send(NULL, reply, NULL);
-
-fail:
-        unit_file_list_free(h);
-        return r;
 }
 
 static int method_list_unit_files(sd_bus_message *message, void *userdata, sd_bus_error *error) {