diff mbox series

scripts: on fail realloc function does not free orig res but null it

Message ID 20240204014425.334193-1-m.belouarga@technologyandstrategy.com
State Accepted
Headers show
Series scripts: on fail realloc function does not free orig res but null it | expand

Commit Message

Mohamed Belouarga Feb. 4, 2024, 1:44 a.m. UTC
From: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>

When a fail occurs, realloc function does null res, but does not free
the original res.

Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
---
 scripts/kconfig/symbol.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 11eba65..61ce57d 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -873,6 +873,7 @@  const char *sym_expand_string_value(const char *in)
 {
 	const char *src;
 	char *res;
+	char *tmp_res;
 	size_t reslen;
 
 	reslen = strlen(in) + 1;
@@ -902,7 +903,10 @@  const char *sym_expand_string_value(const char *in)
 		newlen = strlen(res) + strlen(symval) + strlen(src) + 1;
 		if (newlen > reslen) {
 			reslen = newlen;
-			res = realloc(res, reslen);
+			tmp_res = realloc(res, reslen);
+			if (!tmp_res)
+				free(res);
+			res = tmp_res;
 		}
 
 		strcat(res, symval);