From: Ruben Kerkhof Date: Fri, 4 Dec 2015 22:14:06 +0000 (+0100) Subject: configfile.c: close dir on error X-Git-Tag: collectd-5.5.1~31^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9758016d4d7ba5bcd74bd16f04ea8c98ca45c533;p=collectd.git configfile.c: close dir on error CID #38006 Signed-off-by: Florian Forster --- 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