From 9758016d4d7ba5bcd74bd16f04ea8c98ca45c533 Mon Sep 17 00:00:00 2001 From: Ruben Kerkhof Date: Fri, 4 Dec 2015 23:14:06 +0100 Subject: [PATCH] configfile.c: close dir on error CID #38006 Signed-off-by: Florian Forster --- src/configfile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/configfile.c b/src/configfile.c index 32629e08..8139c631 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -703,6 +703,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, if (root == NULL) { ERROR ("configfile: malloc failed."); + closedir (dh); return (NULL); } memset (root, 0, sizeof (oconfig_item_t)); @@ -722,6 +723,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, ERROR ("configfile: Not including `%s/%s' because its" " name is too long.", dir, de->d_name); + closedir (dh); for (i = 0; i < filenames_num; ++i) free (filenames[i]); free (filenames); @@ -734,6 +736,7 @@ static oconfig_item_t *cf_read_dir (const char *dir, filenames_num * sizeof (*filenames)); if (tmp == NULL) { ERROR ("configfile: realloc failed."); + closedir (dh); for (i = 0; i < filenames_num - 1; ++i) free (filenames[i]); free (filenames); @@ -746,7 +749,10 @@ static oconfig_item_t *cf_read_dir (const char *dir, } if (filenames == NULL) + { + closedir (dh); return (root); + } qsort ((void *) filenames, filenames_num, sizeof (*filenames), cf_compare_string); @@ -771,11 +777,12 @@ static oconfig_item_t *cf_read_dir (const char *dir, free (name); } + closedir (dh); free(filenames); return (root); } /* oconfig_item_t *cf_read_dir */ -/* +/* * cf_read_generic * * Path is stat'ed and either cf_read_file or cf_read_dir is called -- 2.11.0