From: Dmitriy Yakovlev Date: Tue, 7 Feb 2017 02:51:06 +0000 (+0300) Subject: cfgfile: fix uninitialized variable on load error X-Git-Tag: spdx-start~4483 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e7ee2ca1c9078b06ba64342ef8ce43a8022ec236;p=dpdk.git cfgfile: fix uninitialized variable on load error Uninitialized scalar variable. Using uninitialized value cfg->sections[curr_section]->num_entries when calling rte_cfgfile_close. And memory in variables cfg->sections[curr_section], sect->entries[curr_entry] maybe not equal NULL. We must decrement counters curr_section, curr_entry when failed to realloc. Fixes: eaafbad419bf ("cfgfile: library to interpret config files") Signed-off-by: Dmitriy Yakovlev Acked-by: Cristian Dumitrescu --- diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index d72052a08e..829109a77a 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -151,6 +151,7 @@ rte_cfgfile_load(const char *filename, int flags) sizeof(*cfg) + sizeof(cfg->sections[0]) * allocated_sections); if (n_cfg == NULL) { + curr_section--; printf("Error - no more memory\n"); goto error1; } @@ -198,6 +199,7 @@ rte_cfgfile_load(const char *filename, int flags) sizeof(sect->entries[0]) * allocated_entries); if (n_sect == NULL) { + curr_entry--; printf("Error - no more memory\n"); goto error1; } @@ -233,6 +235,8 @@ rte_cfgfile_load(const char *filename, int flags) error1: cfg->num_sections = curr_section + 1; + if (curr_section >= 0) + cfg->sections[curr_section]->num_entries = curr_entry + 1; rte_cfgfile_close(cfg); error2: fclose(f);