Merge pull request #1596 from rubenk/fix-a-few-more-prototypes
[collectd.git] / src / configfile.c
index c389ad1..8139c63 100644 (file)
@@ -610,8 +610,11 @@ static int cf_include_all (oconfig_item_t *root, int depth)
                        return (-1);
 
                /* Now replace the i'th child in `root' with `new'. */
-               if (cf_ci_replace_child (root, new, i) < 0)
+               if (cf_ci_replace_child (root, new, i) < 0) {
+                       sfree (new->values);
+                       sfree (new);
                        return (-1);
+               }
 
                /* ... and go back to the new i'th child. */
                --i;
@@ -700,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));
@@ -719,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);
@@ -731,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);
@@ -743,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);
@@ -768,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