diff options
author | Mukund Sivaraman <muks@banu.com> | 2010-01-16 11:09:14 +0530 |
---|---|---|
committer | Mukund Sivaraman <muks@banu.com> | 2010-01-16 11:09:14 +0530 |
commit | 09d11ace607419e9646042bed19d3b40006dcd6a (patch) | |
tree | 26ce05eb8b327d48378714b20d2e9e05bed40af4 | |
parent | bf820013df8510f72ae916945d08a68065599066 (diff) | |
download | tinyproxy-09d11ace607419e9646042bed19d3b40006dcd6a.tar.gz tinyproxy-09d11ace607419e9646042bed19d3b40006dcd6a.zip |
Fix leak of file handle in load_config_file()
-rw-r--r-- | src/conf.c | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -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, |