kmodloader: fix GCC fanalyzer warnings
authorRosen Penev <rosenp@gmail.com>
Mon, 18 Jul 2022 22:12:38 +0000 (15:12 -0700)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 13 Aug 2022 16:51:07 +0000 (18:51 +0200)
memory leaks and missing NULL checks.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
kmodloader.c

index 4b2ffa76770052bdb60a1385a33cc70b8e29472c..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;
        }
@@ -583,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;
@@ -1164,6 +1174,8 @@ load_options(void)
                        continue;
                }
        }
+
+       fclose(f);
 }
 
 int main(int argc, char **argv)