]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
refactor(dracut-install): add Hashmap cleanup function
authorAdrien Thierry <athierry@redhat.com>
Mon, 21 Nov 2022 16:14:23 +0000 (11:14 -0500)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Mon, 13 Feb 2023 13:29:12 +0000 (13:29 +0000)
This is prep work for adding support for fw_devlink suppliers
dependencies.

Signed-off-by: Adrien Thierry <athierry@redhat.com>
src/install/dracut-install.c

index b008614f93f15a23738753197dc42efd6978d4fe..81fd37f5e58ecd1787fb5d7b4990fbdc28861779 100644 (file)
@@ -96,6 +96,12 @@ static bool arg_mod_filter_noname = false;
 static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst);
 static int install_dependent_modules(struct kmod_list *modlist);
 
+static void item_free(char *i)
+{
+        assert(i);
+        free(i);
+}
+
 static inline void kmod_module_unrefp(struct kmod_module **p)
 {
         if (*p)
@@ -145,6 +151,18 @@ static inline void fts_closep(FTS **p)
 
 #define _cleanup_globfree_ _cleanup_(globfree)
 
+static inline void destroy_hashmap(Hashmap **hashmap)
+{
+        void *i = NULL;
+
+        while ((i = hashmap_steal_first(*hashmap)))
+                item_free(i);
+
+        hashmap_free(*hashmap);
+}
+
+#define _cleanup_destroy_hashmap_ _cleanup_(destroy_hashmap)
+
 static size_t dir_len(char const *file)
 {
         size_t length;
@@ -938,12 +956,6 @@ static int dracut_install(const char *orig_src, const char *orig_dst, bool isdir
         return ret;
 }
 
-static void item_free(char *i)
-{
-        assert(i);
-        free(i);
-}
-
 static void usage(int status)
 {
         /*                                                                                */