diff --git a/src/config_file.c b/src/config_file.c index 09bd26a..632d959 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -68,16 +68,18 @@ void config_file_read(ConfigFile *config, const char *path) { char *line; char *rest; - file_read(&file, path); + config->map = NULL; - config->map = hashmap_new(sizeof(ConfigFileItem), 0, 0, 0, item_hash, - item_compare, NULL, NULL); + file_read(&file, path); if (file.error) { config->error = true; return; } + config->map = hashmap_new(sizeof(ConfigFileItem), 0, 0, 0, item_hash, + item_compare, NULL, NULL); + config->error = false; line = strtok_r(file.content, "\n", &rest); @@ -138,4 +140,8 @@ unsigned int config_file_get_int(const ConfigFile *config, const char *key, return (unsigned int)atoi(item->value); } -void config_file_free(const ConfigFile *config) { hashmap_free(config->map); } +void config_file_free(const ConfigFile *config) { + if (config->map != NULL) { + hashmap_free(config->map); + } +}