From 811ca6c2234a3d13efef55947a9cff8bef56ceb7 Mon Sep 17 00:00:00 2001 From: Tony Ambardar Date: Mon, 15 Jan 2024 12:29:48 -0800 Subject: [PATCH] kmodloader: fix memory leak in scan_loaded_modules() Commit 4c7b720b9c63 fixed some error-handling paths but introduced another memory leak; update and fix. Fixes: 4c7b720b9c63 ("kmodloader: fix GCC fanalyzer warnings") Signed-off-by: Tony Ambardar --- kmodloader.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kmodloader.c b/kmodloader.c index 259ac52..0afc795 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -311,12 +311,13 @@ static int scan_loaded_modules(void) { size_t buf_len = 0; char *buf = NULL; + int rv = -1; FILE *fp; fp = fopen("/proc/modules", "r"); if (!fp) { ULOG_ERR("failed to open /proc/modules\n"); - return -1; + goto out; } while (getline(&buf, &buf_len, fp) > 0) { @@ -338,16 +339,18 @@ static int scan_loaded_modules(void) } if (!n) { ULOG_ERR("Failed to allocate memory for module\n"); - return -1; + goto out; } n->usage = m.usage; n->state = LOADED; } + rv = 0; +out: free(buf); fclose(fp); - return 0; + return rv; } static struct module* get_module_info(const char *module, const char *name) -- 2.30.2