From f5dd5217d6277739b6208771b45787cddd323576 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20=C5=A0tetiar?= Date: Mon, 4 Nov 2019 19:46:13 +0100 Subject: [PATCH] cli: fix realloc issue spotted by cppcheck MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Cppcheck 1.90 dev reports following: cli.c:117:4: error: Common realloc mistake: 'typestr' nulled but not freed upon failure [memleakOnRealloc] typestr = realloc(typestr, maxlen); ^ Signed-off-by: Petr Å tetiar --- cli.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli.c b/cli.c index f8b45db..1ce4d5e 100644 --- a/cli.c +++ b/cli.c @@ -113,8 +113,16 @@ uci_lookup_section_ref(struct uci_section *s) maxlen = strlen(s->type) + 1 + 2 + 10; if (!typestr) { typestr = malloc(maxlen); + if (!typestr) + return NULL; } else { - typestr = realloc(typestr, maxlen); + void *p = realloc(typestr, maxlen); + if (!p) { + free(typestr); + return NULL; + } + + typestr = p; } if (typestr) -- 2.30.2