summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2019-11-05 00:43:46 +0100
committerPetr Štetiar <ynezz@true.cz>2019-11-14 17:11:34 +0100
commita2cab3b088a29b885e33b923edb062badfb92346 (patch)
treedb3bd265319119fc04a29c5a68c1cae98ef37578
parent9cf978bc79641691f0c603c71fcfa98c1626ce59 (diff)
downloaduci-a2cab3b088a29b885e33b923edb062badfb92346.tar.gz
ucimap: fix possible use of memory after it is freed
scan-build from clang version 9 has reported following issue: ucimap.c:710:8: warning: Use of memory after it is freed err = ucimap_parse_options(map, sm, sd, s); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Petr Štetiar <ynezz@true.cz>
-rw-r--r--ucimap.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/ucimap.c b/ucimap.c
index d5fd5c4..7c2b043 100644
--- a/ucimap.c
+++ b/ucimap.c
@@ -490,16 +490,21 @@ ucimap_add_section_list(struct uci_map *map, struct ucimap_section_data *sd)
map->sdata_tail = &sd->next;
}
-static void
+static int
ucimap_add_section(struct ucimap_section_data *sd)
{
+ int r;
struct uci_map *map = sd->map;
sd->next = NULL;
- if (sd->sm->add(map, ucimap_section_ptr(sd)) < 0)
+ r = sd->sm->add(map, ucimap_section_ptr(sd));
+ if (r < 0) {
ucimap_free_section(map, sd);
- else
+ return r;
+ } else
ucimap_add_section_list(map, sd);
+
+ return 0;
}
#ifdef UCI_DEBUG
@@ -702,7 +707,9 @@ ucimap_parse_section(struct uci_map *map, struct uci_sectionmap *sm, struct ucim
goto error;
if (map->parsed) {
- ucimap_add_section(sd);
+ err = ucimap_add_section(sd);
+ if (err)
+ return err;
} else {
ucimap_add_section_list(map, sd);
}