X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=ucimap.c;h=776a30439ef2ac9839e3cd5d6f5e25c4bdfb2e99;hp=7c4fb0240790aeb6c2386aa8c7deed8824bfda6d;hb=9d8e1fe4857c1c3e8f1a2e2ae59ef9c4790adb39;hpb=25f9dbfe7bba18ac6c9b2f31e55c19be57f4eee0 diff --git a/ucimap.c b/ucimap.c index 7c4fb02..776a304 100644 --- a/ucimap.c +++ b/ucimap.c @@ -9,7 +9,7 @@ * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU Lesser General Public License for more details. */ /* @@ -162,9 +162,10 @@ ucimap_free_section(struct uci_map *map, struct ucimap_section_data *sd) void ucimap_cleanup(struct uci_map *map) { - struct ucimap_section_data *sd; + struct ucimap_section_data *sd, *sd_next; - for (sd = map->sdata; sd; sd = sd->next) { + for (sd = map->sdata; sd; sd = sd_next) { + sd_next = sd->next; ucimap_free_section(map, sd); } } @@ -207,7 +208,6 @@ static bool ucimap_handle_fixup(struct uci_map *map, struct ucimap_fixup *f) { void *ptr = ucimap_find_section(map, f); - struct ucimap_list *list; union ucimap_data *data; if (!ptr) @@ -218,7 +218,6 @@ ucimap_handle_fixup(struct uci_map *map, struct ucimap_fixup *f) f->data->ptr = ptr; break; case UCIMAP_LIST: - list = f->data->list; data = ucimap_list_append(f->data->list); if (!data) return false; @@ -276,6 +275,8 @@ ucimap_resize_list(struct ucimap_section_data *sd, struct ucimap_list **list, in if (!*list) { new = calloc(1, size); + if (!new) + return -ENOMEM; ucimap_add_alloc(sd, new); goto set; @@ -294,6 +295,9 @@ realloc: offset = (items - (*list)->size) * sizeof(union ucimap_data); a->ptr = realloc(a->ptr, size); + if (!a->ptr) + return -ENOMEM; + if (offset) memset((char *) a->ptr + offset, 0, size - offset); new = a->ptr; @@ -310,6 +314,7 @@ ucimap_add_fixup(struct ucimap_section_data *sd, union ucimap_data *data, struct struct ucimap_fixup *f, tmp; struct uci_map *map = sd->map; + tmp.next = NULL; tmp.sm = om->data.sm; tmp.name = str; tmp.type = om->type; @@ -708,6 +713,8 @@ ucimap_parse_section(struct uci_map *map, struct uci_sectionmap *sm, struct ucim return 0; error_mem: + if (sd->alloc_custom) + free(sd->alloc_custom); if (sd->allocmap) free(sd->allocmap); free(sd);