[PATCH 2/2] ubox: fix bad realloc usage

Rosen Penev rosenp at gmail.com
Sun Jul 17 19:24: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 bc5f20c..5f8c9c1 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -356,6 +356,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;
@@ -398,12 +399,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