diff options
author | Petr Štetiar <ynezz@true.cz> | 2019-11-04 19:46:13 +0100 |
---|---|---|
committer | Petr Štetiar <ynezz@true.cz> | 2019-11-14 17:11:34 +0100 |
commit | f5dd5217d6277739b6208771b45787cddd323576 (patch) | |
tree | 6cee1383f36fbdb3ad79f36f347b07c58d73b233 | |
parent | af59f86a0db914db60243563956f20e2c0850213 (diff) | |
download | uci-f5dd5217d6277739b6208771b45787cddd323576.tar.gz |
cli: fix realloc issue spotted by cppcheck
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 <ynezz@true.cz>
-rw-r--r-- | cli.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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) |