diff mbox series

[PATCHv2,2/2] ubox: fix GCC fanalyzer warnings

Message ID 20220718221238.5350-2-rosenp@gmail.com
State Accepted
Delegated to: Hauke Mehrtens
Headers show
Series [PATCHv2,1/2] ubox: fix bad realloc usage | expand

Commit Message

Rosen Penev July 18, 2022, 10:12 p.m. UTC
memory leaks and missing NULL checks.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v2: remove null check for free
 kmodloader.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/kmodloader.c b/kmodloader.c
index 4b2ffa7..b2e7a8b 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -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)