From 1c9aaefc119a908c6a9849e96330443c7439e5d1 Mon Sep 17 00:00:00 2001 From: Tony Ambardar Date: Wed, 24 Jan 2024 00:17:06 -0800 Subject: [PATCH] kmodloader: fix memleak adding to avl tree Check avl_insert() return value and free node data on error, otherwise this is observed to directly leak memory. Fixes: 6e3c6dcf922e ("kmodloader: add module alias awareness") Signed-off-by: Tony Ambardar --- kmodloader.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kmodloader.c b/kmodloader.c index 01fa8f6..b705c0c 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -282,8 +282,10 @@ alloc_module_node(const char *name, struct module *m, bool is_alias) mn->avl.key = strcpy(_name, name); mn->m = m; mn->is_alias = is_alias; - avl_insert(&modules, &mn->avl); - m->refcnt += 1; + if (avl_insert(&modules, &mn->avl) == 0) + m->refcnt += 1; + else + free(mn); } return mn; } -- 2.30.2