From a788770a0febfe582dfd7fdf3b264eb6181d2681 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Sun, 29 Jan 2017 14:11:20 +0200 Subject: [PATCH] Add the ability to call load_settings more than once free_ini() didn't properly reset `section_count` and `sections` which caused a segfault if load_ini_file was called multiple times in the same run. --- src/option_parser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/option_parser.c b/src/option_parser.c index 48d92e0..e33454c 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -50,6 +50,7 @@ section_t *new_section(char *name) section_count++; sections = realloc(sections, sizeof(section_t) * section_count); + if(sections == NULL) die("Unable to allocate memory.\n", 1); sections[section_count - 1].name = g_strdup(name); sections[section_count - 1].entries = NULL; sections[section_count - 1].entry_count = 0; @@ -67,6 +68,8 @@ void free_ini(void) free(sections[i].name); } free(sections); + section_count = 0; + sections = NULL; } section_t *get_section(char *name)