Blame 0063-dracut-install-make-use-of-_cleanup_-macros-and-impr.patch

Harald Hoyer b38677
From eab32bda801e539c276f1b18e7c2b691eeab3d14 Mon Sep 17 00:00:00 2001
Harald Hoyer b38677
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer b38677
Date: Fri, 15 Apr 2016 15:29:52 +0200
Harald Hoyer b38677
Subject: [PATCH] dracut-install: make use of _cleanup_ macros and improve
Harald Hoyer b38677
 hostonly check
Harald Hoyer b38677
Harald Hoyer b38677
If a module is renamed or another module takes care of the old one,
Harald Hoyer b38677
all of the alias strings have to be checked against the current set of
Harald Hoyer b38677
loaded modules.
Harald Hoyer b38677
Harald Hoyer b38677
This is still incomplete, because to be absolutely correct, all the
Harald Hoyer b38677
/sys/*...*/modalias files would have to be checked, if they match the
Harald Hoyer b38677
modules alias strings.
Harald Hoyer b38677
---
Harald Hoyer b38677
 install/dracut-install.c | 180 ++++++++++++++++++++++++++++++++++-------------
Harald Hoyer b38677
 1 file changed, 131 insertions(+), 49 deletions(-)
Harald Hoyer b38677
Harald Hoyer b38677
diff --git a/install/dracut-install.c b/install/dracut-install.c
Harald Hoyer b38677
index bef08da..9a0d53f 100644
Harald Hoyer b38677
--- a/install/dracut-install.c
Harald Hoyer b38677
+++ b/install/dracut-install.c
Harald Hoyer b38677
@@ -66,6 +66,7 @@ static char *logfile = NULL;
Harald Hoyer b38677
 FILE *logfile_f = NULL;
Harald Hoyer b38677
 static Hashmap *items = NULL;
Harald Hoyer b38677
 static Hashmap *items_failed = NULL;
Harald Hoyer b38677
+static Hashmap *modules_loaded = NULL;
Harald Hoyer b38677
 static regex_t mod_filter_path;
Harald Hoyer b38677
 static regex_t mod_filter_nopath;
Harald Hoyer b38677
 static regex_t mod_filter_symbol;
Harald Hoyer b38677
@@ -79,6 +80,39 @@ static bool arg_mod_filter_noname = false;
Harald Hoyer b38677
 
Harald Hoyer b38677
 static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst);
Harald Hoyer b38677
 
Harald Hoyer b38677
+
Harald Hoyer b38677
+
Harald Hoyer b38677
+static inline void kmod_module_unref_listp(struct kmod_list **p) {
Harald Hoyer b38677
+        if (*p)
Harald Hoyer b38677
+                kmod_module_unref_list(*p);
Harald Hoyer b38677
+}
Harald Hoyer b38677
+#define _cleanup_kmod_module_unref_list_ _cleanup_(kmod_module_unref_listp)
Harald Hoyer b38677
+
Harald Hoyer b38677
+static inline void kmod_module_info_free_listp(struct kmod_list **p) {
Harald Hoyer b38677
+        if (*p)
Harald Hoyer b38677
+                kmod_module_info_free_list(*p);
Harald Hoyer b38677
+}
Harald Hoyer b38677
+#define _cleanup_kmod_module_info_free_list_ _cleanup_(kmod_module_info_free_listp)
Harald Hoyer b38677
+
Harald Hoyer b38677
+static inline void kmod_unrefp(struct kmod_ctx **p) {
Harald Hoyer b38677
+        kmod_unref(*p);
Harald Hoyer b38677
+}
Harald Hoyer b38677
+#define _cleanup_kmod_unref_ _cleanup_(kmod_unrefp)
Harald Hoyer b38677
+
Harald Hoyer b38677
+static inline void kmod_module_dependency_symbols_free_listp(struct kmod_list **p) {
Harald Hoyer b38677
+        if (*p)
Harald Hoyer b38677
+                kmod_module_dependency_symbols_free_list(*p);
Harald Hoyer b38677
+}
Harald Hoyer b38677
+#define _cleanup_kmod_module_dependency_symbols_free_list_ _cleanup_(kmod_module_dependency_symbols_free_listp)
Harald Hoyer b38677
+
Harald Hoyer b38677
+static inline void fts_closep(FTS **p) {
Harald Hoyer b38677
+        if (*p)
Harald Hoyer b38677
+                fts_close(*p);
Harald Hoyer b38677
+}
Harald Hoyer b38677
+#define _cleanup_fts_close_ _cleanup_(fts_closep)
Harald Hoyer b38677
+
Harald Hoyer b38677
+
Harald Hoyer b38677
+
Harald Hoyer b38677
 static size_t dir_len(char const *file)
Harald Hoyer b38677
 {
Harald Hoyer b38677
         size_t length;
Harald Hoyer b38677
@@ -1058,7 +1092,8 @@ static int install_all(int argc, char **argv)
Harald Hoyer b38677
 
Harald Hoyer b38677
 static int install_firmware(struct kmod_module *mod)
Harald Hoyer b38677
 {
Harald Hoyer b38677
-        struct kmod_list *l, *list = NULL;
Harald Hoyer b38677
+        struct kmod_list *l;
Harald Hoyer b38677
+        _cleanup_kmod_module_info_free_list_ struct kmod_list *list = NULL;
Harald Hoyer b38677
         int ret;
Harald Hoyer b38677
 
Harald Hoyer b38677
         char **q;
Harald Hoyer b38677
@@ -1072,7 +1107,6 @@ static int install_firmware(struct kmod_module *mod)
Harald Hoyer b38677
         kmod_list_foreach(l, list) {
Harald Hoyer b38677
                 const char *key = kmod_module_info_get_key(l);
Harald Hoyer b38677
                 const char *value = NULL;
Harald Hoyer b38677
-                char *fwpath = NULL;
Harald Hoyer b38677
 
Harald Hoyer b38677
                 if (!streq("firmware", key))
Harald Hoyer b38677
                         continue;
Harald Hoyer b38677
@@ -1081,6 +1115,7 @@ static int install_firmware(struct kmod_module *mod)
Harald Hoyer b38677
                 log_debug("Firmware %s", value);
Harald Hoyer b38677
                 ret = -1;
Harald Hoyer b38677
                 STRV_FOREACH(q, firmwaredirs) {
Harald Hoyer b38677
+                        _cleanup_free_ char *fwpath = NULL;
Harald Hoyer b38677
                         struct stat sb;
Harald Hoyer b38677
                         int r;
Harald Hoyer b38677
 
Harald Hoyer b38677
@@ -1092,8 +1127,6 @@ static int install_firmware(struct kmod_module *mod)
Harald Hoyer b38677
 
Harald Hoyer b38677
                         if (stat(fwpath, &sb) != 0) {
Harald Hoyer b38677
                                 log_debug("stat(%s) != 0", fwpath);
Harald Hoyer b38677
-                                free(fwpath);
Harald Hoyer b38677
-                                fwpath = NULL;
Harald Hoyer b38677
                                 continue;
Harald Hoyer b38677
                         }
Harald Hoyer b38677
 
Harald Hoyer b38677
@@ -1111,7 +1144,8 @@ static int install_firmware(struct kmod_module *mod)
Harald Hoyer b38677
 
Harald Hoyer b38677
 static bool check_module_symbols(struct kmod_module *mod)
Harald Hoyer b38677
 {
Harald Hoyer b38677
-        struct kmod_list *itr, *deplist = NULL;
Harald Hoyer b38677
+        struct kmod_list *itr;
Harald Hoyer b38677
+        _cleanup_kmod_module_dependency_symbols_free_list_ struct kmod_list *deplist = NULL;
Harald Hoyer b38677
 
Harald Hoyer b38677
         if (!arg_mod_filter_symbol && !arg_mod_filter_nosymbol)
Harald Hoyer b38677
                 return true;
Harald Hoyer b38677
@@ -1128,7 +1162,6 @@ static bool check_module_symbols(struct kmod_module *mod)
Harald Hoyer b38677
                         const char *symbol = kmod_module_symbol_get_symbol(itr);
Harald Hoyer b38677
                         // log_debug("Checking symbol %s", symbol);
Harald Hoyer b38677
                         if (regexec(&mod_filter_nosymbol, symbol, 0, NULL, 0) == 0) {
Harald Hoyer b38677
-                                kmod_module_dependency_symbols_free_list(deplist);
Harald Hoyer b38677
                                 log_debug("Module %s: symbol %s matched exclusion filter", kmod_module_get_name(mod), symbol);
Harald Hoyer b38677
                                 return false;
Harald Hoyer b38677
                         }
Harald Hoyer b38677
@@ -1140,20 +1173,16 @@ static bool check_module_symbols(struct kmod_module *mod)
Harald Hoyer b38677
                         const char *symbol = kmod_module_dependency_symbol_get_symbol(itr);
Harald Hoyer b38677
                         // log_debug("Checking symbol %s", symbol);
Harald Hoyer b38677
                         if (regexec(&mod_filter_symbol, symbol, 0, NULL, 0) == 0) {
Harald Hoyer b38677
-                                kmod_module_dependency_symbols_free_list(deplist);
Harald Hoyer b38677
                                 log_debug("Module %s: symbol %s matched inclusion filter", kmod_module_get_name(mod), symbol);
Harald Hoyer b38677
                                 return true;
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                 }
Harald Hoyer b38677
-                kmod_module_dependency_symbols_free_list(deplist);
Harald Hoyer b38677
                 return false;
Harald Hoyer b38677
         }
Harald Hoyer b38677
 
Harald Hoyer b38677
-        kmod_module_dependency_symbols_free_list(deplist);
Harald Hoyer b38677
         return true;
Harald Hoyer b38677
 }
Harald Hoyer b38677
 
Harald Hoyer b38677
-
Harald Hoyer b38677
 static bool check_module_path(const char *path)
Harald Hoyer b38677
 {
Harald Hoyer b38677
         if (arg_mod_filter_nopath && (regexec(&mod_filter_nopath, path, 0, NULL, 0) == 0)) {
Harald Hoyer b38677
@@ -1168,14 +1197,23 @@ static bool check_module_path(const char *path)
Harald Hoyer b38677
         return true;
Harald Hoyer b38677
 }
Harald Hoyer b38677
 
Harald Hoyer b38677
+static bool check_module_hostonly(struct kmod_module *mod)
Harald Hoyer b38677
+{
Harald Hoyer b38677
+        const char *name = kmod_module_get_name(mod);
Harald Hoyer b38677
+
Harald Hoyer b38677
+        if (check_hashmap(modules_loaded, name))
Harald Hoyer b38677
+                return true;
Harald Hoyer b38677
+
Harald Hoyer b38677
+        return false;
Harald Hoyer b38677
+}
Harald Hoyer b38677
+
Harald Hoyer b38677
 static int install_module(struct kmod_module *mod)
Harald Hoyer b38677
 {
Harald Hoyer b38677
         int ret = 0;
Harald Hoyer b38677
-        int state;
Harald Hoyer b38677
-        struct kmod_list *itr, *modlist = NULL;
Harald Hoyer b38677
+        struct kmod_list *itr;
Harald Hoyer b38677
+        _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
Harald Hoyer b38677
         const char *path = NULL;
Harald Hoyer b38677
         const char *name = NULL;
Harald Hoyer b38677
-        state = kmod_module_get_initstate(mod);
Harald Hoyer b38677
 
Harald Hoyer b38677
         name = kmod_module_get_name(mod);
Harald Hoyer b38677
         if (arg_mod_filter_noname && (regexec(&mod_filter_noname, name, 0, NULL, 0) == 0)) {
Harald Hoyer b38677
@@ -1183,7 +1221,7 @@ static int install_module(struct kmod_module *mod)
Harald Hoyer b38677
                 return 0;
Harald Hoyer b38677
         }
Harald Hoyer b38677
 
Harald Hoyer b38677
-        if (arg_hostonly && (state != KMOD_MODULE_BUILTIN) && (state != KMOD_MODULE_LIVE)) {
Harald Hoyer b38677
+        if (arg_hostonly && ! check_module_hostonly(mod)) {
Harald Hoyer b38677
                 log_debug("dracut_install '%s' not hostonly", name);
Harald Hoyer b38677
                 return 0;
Harald Hoyer b38677
         }
Harald Hoyer b38677
@@ -1232,15 +1270,17 @@ static int install_module(struct kmod_module *mod)
Harald Hoyer b38677
                 }
Harald Hoyer b38677
                 kmod_module_unref(mod);
Harald Hoyer b38677
         }
Harald Hoyer b38677
-        kmod_module_unref_list(modlist);
Harald Hoyer b38677
 
Harald Hoyer b38677
         return ret;
Harald Hoyer b38677
 }
Harald Hoyer b38677
 
Harald Hoyer b38677
 static int install_modules(int argc, char **argv)
Harald Hoyer b38677
 {
Harald Hoyer b38677
-        struct kmod_ctx *ctx = NULL;
Harald Hoyer b38677
-        struct kmod_list *itr, *modlist = NULL;
Harald Hoyer b38677
+        _cleanup_kmod_unref_ struct kmod_ctx *ctx = NULL;
Harald Hoyer b38677
+        struct kmod_list *loaded_list = NULL;
Harald Hoyer b38677
+        struct kmod_list *itr, *l;
Harald Hoyer b38677
+        int err;
Harald Hoyer b38677
+
Harald Hoyer b38677
         struct kmod_module *mod = NULL, *mod_o = NULL;
Harald Hoyer b38677
 
Harald Hoyer b38677
         const char *modname = NULL;
Harald Hoyer b38677
@@ -1248,12 +1288,48 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
 
Harald Hoyer b38677
         ctx = kmod_new(kerneldir, NULL);
Harald Hoyer b38677
 
Harald Hoyer b38677
+        err = kmod_module_new_from_loaded(ctx, &loaded_list);
Harald Hoyer b38677
+        if (err < 0) {
Harald Hoyer b38677
+                errno = err;
Harald Hoyer b38677
+                log_error("Could not get list of loaded modules: %m");
Harald Hoyer b38677
+                return err;
Harald Hoyer b38677
+        }
Harald Hoyer b38677
+
Harald Hoyer b38677
+        kmod_list_foreach(itr, loaded_list) {
Harald Hoyer b38677
+                _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
Harald Hoyer b38677
+
Harald Hoyer b38677
+                struct kmod_module *mod = kmod_module_get_module(itr);
Harald Hoyer b38677
+                char *name = strdup(kmod_module_get_name(mod));
Harald Hoyer b38677
+                hashmap_put(modules_loaded, name, name);
Harald Hoyer b38677
+                kmod_module_unref(mod);
Harald Hoyer b38677
+
Harald Hoyer b38677
+                /* also put the modules from the new kernel in the hashmap,
Harald Hoyer b38677
+                 * which resolve the name as an alias, in case a kernel module is
Harald Hoyer b38677
+                 * renamed.
Harald Hoyer b38677
+                 */
Harald Hoyer b38677
+                err = kmod_module_new_from_lookup(ctx, name, &modlist);
Harald Hoyer b38677
+                if (err < 0)
Harald Hoyer b38677
+                        continue;
Harald Hoyer b38677
+                if (!modlist)
Harald Hoyer b38677
+                        continue;
Harald Hoyer b38677
+                kmod_list_foreach(l, modlist) {
Harald Hoyer b38677
+                        mod = kmod_module_get_module(l);
Harald Hoyer b38677
+                        char *name = strdup(kmod_module_get_name(mod));
Harald Hoyer b38677
+                        hashmap_put(modules_loaded, name, name);
Harald Hoyer b38677
+                        kmod_module_unref(mod);
Harald Hoyer b38677
+                }
Harald Hoyer b38677
+        }
Harald Hoyer b38677
+        kmod_module_unref_list(loaded_list);
Harald Hoyer b38677
+
Harald Hoyer b38677
         for (i = 0; i < argc; i++) {
Harald Hoyer b38677
                 int r = 0;
Harald Hoyer b38677
                 int ret = -1;
Harald Hoyer b38677
+
Harald Hoyer b38677
                 log_debug("Handle module '%s'", argv[i]);
Harald Hoyer b38677
 
Harald Hoyer b38677
                 if (argv[i][0] == '/') {
Harald Hoyer b38677
+                        _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
Harald Hoyer b38677
+
Harald Hoyer b38677
                         r = kmod_module_new_from_path(ctx, argv[i], &mod_o);
Harald Hoyer b38677
                         if (r < 0) {
Harald Hoyer b38677
                                 log_debug("Failed to lookup modules path '%s': %m", argv[i]);
Harald Hoyer b38677
@@ -1263,6 +1339,7 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                         /* Check, if we have to load another module with that name instead */
Harald Hoyer b38677
                         modname = kmod_module_get_name(mod_o);
Harald Hoyer b38677
+
Harald Hoyer b38677
                         if (!modname) {
Harald Hoyer b38677
                                 if (!arg_optional) {
Harald Hoyer b38677
                                         if (!arg_silent)
Harald Hoyer b38677
@@ -1272,8 +1349,11 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                                 log_info("Failed to get name for module '%s'", argv[i]);
Harald Hoyer b38677
                                 continue;
Harald Hoyer b38677
                         }
Harald Hoyer b38677
+
Harald Hoyer b38677
                         r = kmod_module_new_from_lookup(ctx, modname, &modlist);
Harald Hoyer b38677
                         kmod_module_unref(mod_o);
Harald Hoyer b38677
+                        mod_o = NULL;
Harald Hoyer b38677
+
Harald Hoyer b38677
                         if (r < 0) {
Harald Hoyer b38677
                                 if (!arg_optional) {
Harald Hoyer b38677
                                         if (!arg_silent)
Harald Hoyer b38677
@@ -1303,37 +1383,38 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                                 };
Harald Hoyer b38677
                                 ret = ( ret == 0 ? 0 : r );
Harald Hoyer b38677
                         }
Harald Hoyer b38677
-                        kmod_module_unref_list(modlist);
Harald Hoyer b38677
-                        modlist = 0;
Harald Hoyer b38677
                 } else if (argv[i][0] == '=') {
Harald Hoyer b38677
-                        char *path1, *path2, *path3;
Harald Hoyer b38677
-                        FTS *fts;
Harald Hoyer b38677
+                        _cleanup_free_ char *path1 = NULL, *path2 = NULL, *path3 = NULL;
Harald Hoyer b38677
+                        _cleanup_fts_close_ FTS *fts = NULL;
Harald Hoyer b38677
+
Harald Hoyer b38677
                         log_debug("Handling =%s", &argv[i][1]);
Harald Hoyer b38677
                         /* FIXME and add more paths*/
Harald Hoyer b38677
-                        {
Harald Hoyer b38677
-                                int r;
Harald Hoyer b38677
-                                r = asprintf(&path2, "%s/kernel/%s", kerneldir, &argv[i][1]);
Harald Hoyer b38677
-                                if (r < 0) {
Harald Hoyer b38677
-                                        log_error("Out of memory!");
Harald Hoyer b38677
-                                        exit(EXIT_FAILURE);
Harald Hoyer b38677
-                                }
Harald Hoyer b38677
+                        r = asprintf(&path2, "%s/kernel/%s", kerneldir, &argv[i][1]);
Harald Hoyer b38677
+                        if (r < 0) {
Harald Hoyer b38677
+                                log_error("Out of memory!");
Harald Hoyer b38677
+                                exit(EXIT_FAILURE);
Harald Hoyer b38677
+                        }
Harald Hoyer b38677
 
Harald Hoyer b38677
-                                r = asprintf(&path1, "%s/extra/%s", kerneldir, &argv[i][1]);
Harald Hoyer b38677
-                                if (r < 0) {
Harald Hoyer b38677
-                                        log_error("Out of memory!");
Harald Hoyer b38677
-                                        exit(EXIT_FAILURE);
Harald Hoyer b38677
-                                }
Harald Hoyer b38677
+                        r = asprintf(&path1, "%s/extra/%s", kerneldir, &argv[i][1]);
Harald Hoyer b38677
+                        if (r < 0) {
Harald Hoyer b38677
+                                log_error("Out of memory!");
Harald Hoyer b38677
+                                exit(EXIT_FAILURE);
Harald Hoyer b38677
+                        }
Harald Hoyer b38677
 
Harald Hoyer b38677
-                                r = asprintf(&path3, "%s/updates/%s", kerneldir, &argv[i][1]);
Harald Hoyer b38677
-                                if (r < 0) {
Harald Hoyer b38677
-                                        log_error("Out of memory!");
Harald Hoyer b38677
-                                        exit(EXIT_FAILURE);
Harald Hoyer b38677
-                                }
Harald Hoyer b38677
+                        r = asprintf(&path3, "%s/updates/%s", kerneldir, &argv[i][1]);
Harald Hoyer b38677
+                        if (r < 0) {
Harald Hoyer b38677
+                                log_error("Out of memory!");
Harald Hoyer b38677
+                                exit(EXIT_FAILURE);
Harald Hoyer b38677
+                        }
Harald Hoyer b38677
 
Harald Hoyer b38677
+                        {
Harald Hoyer b38677
                                 char *paths[] = { path1, path2, path3, NULL };
Harald Hoyer b38677
                                 fts = fts_open(paths, FTS_COMFOLLOW|FTS_NOCHDIR|FTS_NOSTAT|FTS_LOGICAL, NULL);
Harald Hoyer b38677
                         }
Harald Hoyer b38677
+
Harald Hoyer b38677
                         for (FTSENT *ftsent = fts_read(fts); ftsent != NULL; ftsent = fts_read(fts)) {
Harald Hoyer b38677
+                                _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
Harald Hoyer b38677
+
Harald Hoyer b38677
                                 if((ftsent->fts_info == FTS_D) && !check_module_path(ftsent->fts_accpath)) {
Harald Hoyer b38677
                                         fts_set(fts, ftsent, FTS_SKIP);
Harald Hoyer b38677
                                         log_debug("Skipping %s", ftsent->fts_accpath);
Harald Hoyer b38677
@@ -1356,6 +1437,7 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
 
Harald Hoyer b38677
                                 /* Check, if we have to load another module with that name instead */
Harald Hoyer b38677
                                 modname = kmod_module_get_name(mod_o);
Harald Hoyer b38677
+
Harald Hoyer b38677
                                 if (!modname) {
Harald Hoyer b38677
                                         log_error("Failed to get name for module '%s'", ftsent->fts_accpath);
Harald Hoyer b38677
                                         if (!arg_optional) {
Harald Hoyer b38677
@@ -1365,18 +1447,19 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
                                 r = kmod_module_new_from_lookup(ctx, modname, &modlist);
Harald Hoyer b38677
                                 kmod_module_unref(mod_o);
Harald Hoyer b38677
+                                mod_o = NULL;
Harald Hoyer b38677
+
Harald Hoyer b38677
                                 if (r < 0) {
Harald Hoyer b38677
                                         log_error("Failed to lookup alias '%s': %m", modname);
Harald Hoyer b38677
-                                        kmod_module_unref_list(modlist);
Harald Hoyer b38677
                                         if (!arg_optional) {
Harald Hoyer b38677
                                                 return -ENOENT;
Harald Hoyer b38677
                                         }
Harald Hoyer b38677
                                         continue;
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
+
Harald Hoyer b38677
                                 if (!modlist) {
Harald Hoyer b38677
                                         log_error("Failed to find module '%s' %s", modname,
Harald Hoyer b38677
                                                   ftsent->fts_accpath);
Harald Hoyer b38677
-                                        kmod_module_unref_list(modlist);
Harald Hoyer b38677
                                         if (!arg_optional) {
Harald Hoyer b38677
                                                 return -ENOENT;
Harald Hoyer b38677
                                         }
Harald Hoyer b38677
@@ -1393,18 +1476,14 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                                         };
Harald Hoyer b38677
                                         ret = ( ret == 0 ? 0 : r );
Harald Hoyer b38677
                                 }
Harald Hoyer b38677
-                                kmod_module_unref_list(modlist);
Harald Hoyer b38677
-                                modlist = 0;
Harald Hoyer b38677
                         }
Harald Hoyer b38677
                         if (errno) {
Harald Hoyer b38677
                                 log_error("FTS ERROR: %m");
Harald Hoyer b38677
                         }
Harald Hoyer b38677
-                        fts_close(fts);
Harald Hoyer b38677
-                        free(path1); path1 = NULL;
Harald Hoyer b38677
-                        free(path2); path2 = NULL;
Harald Hoyer b38677
-                        free(path3); path3 = NULL;
Harald Hoyer b38677
                 } else {
Harald Hoyer b38677
+                        _cleanup_kmod_module_unref_list_ struct kmod_list *modlist = NULL;
Harald Hoyer b38677
                         char *modname = argv[i];
Harald Hoyer b38677
+
Harald Hoyer b38677
                         if (endswith(modname, ".ko")) {
Harald Hoyer b38677
                                 int len = strlen(modname);
Harald Hoyer b38677
                                 modname[len-3]=0;
Harald Hoyer b38677
@@ -1443,8 +1522,6 @@ static int install_modules(int argc, char **argv)
Harald Hoyer b38677
                                 };
Harald Hoyer b38677
                                 ret = ( ret == 0 ? 0 : r );
Harald Hoyer b38677
                         }
Harald Hoyer b38677
-                        kmod_module_unref_list(modlist);
Harald Hoyer b38677
-                        modlist = 0;
Harald Hoyer b38677
                 }
Harald Hoyer b38677
 
Harald Hoyer b38677
                 if ((ret != 0) && (!arg_optional)) {
Harald Hoyer b38677
@@ -1513,8 +1590,9 @@ int main(int argc, char **argv)
Harald Hoyer b38677
 
Harald Hoyer b38677
         items = hashmap_new(string_hash_func, string_compare_func);
Harald Hoyer b38677
         items_failed = hashmap_new(string_hash_func, string_compare_func);
Harald Hoyer b38677
+        modules_loaded = hashmap_new(string_hash_func, string_compare_func);
Harald Hoyer b38677
 
Harald Hoyer b38677
-        if (!items || !items_failed) {
Harald Hoyer b38677
+        if (!items || !items_failed || !modules_loaded) {
Harald Hoyer b38677
                 log_error("Out of memory");
Harald Hoyer b38677
                 r = EXIT_FAILURE;
Harald Hoyer b38677
                 goto finish;
Harald Hoyer b38677
@@ -1570,6 +1648,9 @@ int main(int argc, char **argv)
Harald Hoyer b38677
         if (logfile_f)
Harald Hoyer b38677
                 fclose(logfile_f);
Harald Hoyer b38677
 
Harald Hoyer b38677
+        while ((i = hashmap_steal_first(modules_loaded)))
Harald Hoyer b38677
+                item_free(i);
Harald Hoyer b38677
+
Harald Hoyer b38677
         while ((i = hashmap_steal_first(items)))
Harald Hoyer b38677
                 item_free(i);
Harald Hoyer b38677
 
Harald Hoyer b38677
@@ -1578,6 +1659,7 @@ int main(int argc, char **argv)
Harald Hoyer b38677
 
Harald Hoyer b38677
         hashmap_free(items);
Harald Hoyer b38677
         hashmap_free(items_failed);
Harald Hoyer b38677
+        hashmap_free(modules_loaded);
Harald Hoyer b38677
 
Harald Hoyer b38677
         free(destrootdir);
Harald Hoyer b38677
         strv_free(firmwaredirs);