summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMukund Sivaraman <muks@banu.com>2010-01-16 11:09:14 +0530
committerMukund Sivaraman <muks@banu.com>2010-01-16 11:09:14 +0530
commit09d11ace607419e9646042bed19d3b40006dcd6a (patch)
tree26ce05eb8b327d48378714b20d2e9e05bed40af4
parentbf820013df8510f72ae916945d08a68065599066 (diff)
Fix leak of file handle in load_config_file()
-rw-r--r--src/conf.c35
1 files 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,