From f0c3b683270dbce933ef3d2f89d99dea7314ebf6 Mon Sep 17 00:00:00 2001 From: Adrien Thierry Date: Mon, 21 Nov 2022 11:14:23 -0500 Subject: [PATCH] refactor(dracut-install): add Hashmap cleanup function This is prep work for adding support for fw_devlink suppliers dependencies. Signed-off-by: Adrien Thierry --- src/install/dracut-install.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/install/dracut-install.c b/src/install/dracut-install.c index b008614f93..81fd37f5e5 100644 --- a/src/install/dracut-install.c +++ b/src/install/dracut-install.c @@ -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) { /* */