kmodloader: fix GCC fanalyzer warnings
[project/ubox.git] / kmodloader.c
index 63bae5e827bdd25bbd60a4800451928fdb8c0c55..b2e7a8b44089a788e51c281ee5fa8ea05b317f51 100644 (file)
@@ -336,6 +336,11 @@ static int scan_loaded_modules(void)
                        /* possibly a module outside /lib/modules/<ver>/ */
                        n = alloc_module(m.name, NULL, 0, m.depends, m.size);
                }
+               if (!n) {
+                       ULOG_ERR("Failed to allocate memory for module\n");
+                       return -1;
+               }
+
                n->usage = m.usage;
                n->state = LOADED;
        }
@@ -351,6 +356,7 @@ static struct module* get_module_info(const char *module, const char *name)
        unsigned int offset, size;
        char *map = MAP_FAILED, *strings, *dep = NULL;
        const char **aliases = NULL;
+       const char **aliasesr;
        int naliases = 0;
        struct module *m = NULL;
        struct stat s;
@@ -393,12 +399,13 @@ static struct module* get_module_info(const char *module, const char *name)
                if (!strncmp(strings, "depends=", len + 1))
                        dep = sep;
                else if (!strncmp(strings, "alias=", len + 1)) {
-                       aliases = realloc(aliases, sizeof(sep) * (naliases + 1));
-                       if (!aliases) {
+                       aliasesr = realloc(aliases, sizeof(sep) * (naliases + 1));
+                       if (!aliasesr) {
                                ULOG_ERR("out of memory\n");
                                goto out;
                        }
 
+                       aliases = aliasesr;
                        aliases[naliases++] = sep;
                }
                strings = &sep[strlen(sep)];
@@ -581,6 +588,11 @@ static int insert_module(char *path, const char *options)
        struct stat s;
        int fd, ret = -1;
 
+       if (!path) {
+               ULOG_ERR("Path not specified\n");
+               return ret;
+       }
+
        if (stat(path, &s)) {
                ULOG_ERR("missing module %s\n", path);
                return ret;
@@ -1162,6 +1174,8 @@ load_options(void)
                        continue;
                }
        }
+
+       fclose(f);
 }
 
 int main(int argc, char **argv)