From 09d11ace607419e9646042bed19d3b40006dcd6a Mon Sep 17 00:00:00 2001 From: Mukund Sivaraman Date: Sat, 16 Jan 2010 11:09:14 +0530 Subject: Fix leak of file handle in load_config_file() --- src/conf.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/conf.c b/src/conf.c index 786a5b8..26289ba 100644 --- a/src/conf.c +++ b/src/conf.c @@ -387,23 +387,30 @@ static int config_parse (struct config_s *conf, FILE * f) static int load_config_file (const char *config_fname, struct config_s *conf) { FILE *config_file; + int ret = -1; + + do { + config_file = fopen (config_fname, "r"); + if (!config_file) { + fprintf (stderr, + "%s: Could not open config file \"%s\".\n", + PACKAGE, config_fname); + break; + } - config_file = fopen (config_fname, "r"); - if (!config_file) { - fprintf (stderr, - "%s: Could not open config file \"%s\".\n", - PACKAGE, config_fname); - return -1; - } + if (config_compile () || config_parse (conf, config_file)) { + fprintf (stderr, "Unable to parse config file. " + "Not starting.\n"); + break; + } - if (config_compile () || config_parse (conf, config_file)) { - fprintf (stderr, "Unable to parse config file. " - "Not starting.\n"); - return -1; - } + ret = 0; + } while (0); - fclose (config_file); - return 0; + if (config_file) + fclose (config_file); + + return ret; } static void initialize_with_defaults (struct config_s *conf, -- cgit v1.2.3