diff options
author | Rosen Penev <rosenp@gmail.com> | 2022-07-18 15:12:37 -0700 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2022-08-13 18:51:02 +0200 |
commit | fa6cb9a3810f5e609e2f11cd8e0a474f58a990c5 (patch) | |
tree | d640e7e9cd26eef8f257f822d25ac7569603d00f | |
parent | 46a33b8be298e1e700e56f05b5ba4f06daf83efa (diff) | |
download | ubox-fa6cb9a3810f5e609e2f11cd8e0a474f58a990c5.tar.gz |
kmodloader: fix bad realloc usage
Both cppcheck and gcc's -fanalyzer complain here that realloc is being
used improperly.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
-rw-r--r-- | kmodloader.c | 6 |
1 files 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)]; |