[PATCHv2 1/2] ubox: fix bad realloc usage
Rosen Penev
rosenp at gmail.com
Mon Jul 18 15:12:37 PDT 2022
Both cppcheck and gcc's -fanalyzer complain here that realloc is being
used improperly.
Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
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.36.1
More information about the openwrt-devel
mailing list