From 7ea9dc2bdf76ed330a8132d2ccabd5fdba227fdd Mon Sep 17 00:00:00 2001 From: Dmitri Pal <dpal@redhat.com> Date: Wed, 15 Apr 2009 11:58:39 -0400 Subject: INI parser. Better error handling if something bad happens. Tried to use the INI interface and saw that the list of parsing errors can be not NULL but the actual data is cleaned. --- common/ini/ini_config.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c index fd1efb02..7effc042 100644 --- a/common/ini/ini_config.c +++ b/common/ini/ini_config.c @@ -163,7 +163,7 @@ static int ini_to_collection(const char *filename, if (error) { TRACE_ERROR_NUMBER("Failed to create error collection", error); fclose(file); - return EOK; + return error; } created = 1; } @@ -195,7 +195,10 @@ static int ini_to_collection(const char *filename, TRACE_ERROR_NUMBER("Failed to create collection", error); fclose(file); destroy_collection(current_section); - if (created) destroy_collection(*error_list); + if (created) { + destroy_collection(*error_list); + *error_list = NULL; + } return error; } } @@ -209,7 +212,10 @@ static int ini_to_collection(const char *filename, TRACE_ERROR_NUMBER("Failed to add pair to collection", error); fclose(file); destroy_collection(current_section); - if (created) destroy_collection(*error_list); + if (created) { + destroy_collection(*error_list); + *error_list = NULL; + } return error; } break; @@ -231,7 +237,10 @@ static int ini_to_collection(const char *filename, TRACE_ERROR_NUMBER("Failed to add collection", error); fclose(file); destroy_collection(current_section); - if (created) destroy_collection(*error_list); + if (created) { + destroy_collection(*error_list); + *error_list = NULL; + } return error; } } @@ -255,7 +264,10 @@ static int ini_to_collection(const char *filename, TRACE_ERROR_NUMBER("Failed to add error to collection", error); fclose(file); destroy_collection(current_section); - if (created) destroy_collection(*error_list); + if (created) { + destroy_collection(*error_list); + *error_list = NULL; + } return error; } /* Exit if there was an error parsing file */ @@ -277,7 +289,10 @@ static int ini_to_collection(const char *filename, TRACE_ERROR_NUMBER("Failed to add warning to collection", error); fclose(file); destroy_collection(current_section); - if (created) destroy_collection(*error_list); + if (created) { + destroy_collection(*error_list); + *error_list = NULL; + } return error; } /* Exit if we are told to exit on warnings */ -- cgit