From fa6cb9a3810f5e609e2f11cd8e0a474f58a990c5 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 18 Jul 2022 15:12:37 -0700 Subject: [PATCH] kmodloader: fix bad realloc usage Both cppcheck and gcc's -fanalyzer complain here that realloc is being used improperly. Signed-off-by: Rosen Penev --- kmodloader.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kmodloader.c b/kmodloader.c index 63bae5e..4b2ffa7 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -351,6 +351,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 +394,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)]; -- 2.30.2