projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
curl_xml: fix 3 small memory leaks
[collectd.git]
/
src
/
configfile.c
diff --git
a/src/configfile.c
b/src/configfile.c
index
aade476
..
983d995
100644
(file)
--- a/
src/configfile.c
+++ b/
src/configfile.c
@@
-99,6
+99,7
@@
static cf_global_option_t cf_global_options[] =
{"FQDNLookup", NULL, "false"},
{"Interval", NULL, "10"},
{"ReadThreads", NULL, "5"},
{"FQDNLookup", NULL, "false"},
{"Interval", NULL, "10"},
{"ReadThreads", NULL, "5"},
+ {"Timeout", NULL, "2"},
{"PreCacheChain", NULL, "PreCache"},
{"PostCacheChain", NULL, "PostCache"}
};
{"PreCacheChain", NULL, "PreCache"},
{"PostCacheChain", NULL, "PostCache"}
};
@@
-413,6
+414,12
@@
static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src,
/* Resize the memory containing the children to be big enough to hold
* all children. */
/* Resize the memory containing the children to be big enough to hold
* all children. */
+ if (dst->children_num + src->children_num - 1 == 0)
+ {
+ dst->children_num = 0;
+ return (0);
+ }
+
temp = (oconfig_item_t *) realloc (dst->children,
sizeof (oconfig_item_t)
* (dst->children_num + src->children_num - 1));
temp = (oconfig_item_t *) realloc (dst->children,
sizeof (oconfig_item_t)
* (dst->children_num + src->children_num - 1));
@@
-513,7
+520,8
@@
static int cf_include_all (oconfig_item_t *root, int depth)
continue;
/* Now replace the i'th child in `root' with `new'. */
continue;
/* Now replace the i'th child in `root' with `new'. */
- cf_ci_replace_child (root, new, i);
+ if (cf_ci_replace_child (root, new, i) < 0)
+ return (-1);
/* ... and go back to the new i'th child. */
--i;
/* ... and go back to the new i'th child. */
--i;
@@
-575,14
+583,14
@@
static oconfig_item_t *cf_read_dir (const char *dir, int depth)
ERROR ("configfile: malloc failed.");
return (NULL);
}
ERROR ("configfile: malloc failed.");
return (NULL);
}
- memset (root,
'\0'
, sizeof (oconfig_item_t));
+ memset (root,
0
, sizeof (oconfig_item_t));
while ((de = readdir (dh)) != NULL)
{
char name[1024];
char **tmp;
while ((de = readdir (dh)) != NULL)
{
char name[1024];
char **tmp;
- if ((de->d_name[0] == '.') || (de->d_name[0] ==
'\0'
))
+ if ((de->d_name[0] == '.') || (de->d_name[0] ==
0
))
continue;
status = ssnprintf (name, sizeof (name), "%s/%s",
continue;
status = ssnprintf (name, sizeof (name), "%s/%s",
@@
-624,13
+632,11
@@
static oconfig_item_t *cf_read_dir (const char *dir, int depth)
char *name = filenames[i];
temp = cf_read_generic (name, depth);
char *name = filenames[i];
temp = cf_read_generic (name, depth);
- if (temp == NULL) {
- int j;
- for (j = i; j < filenames_num; ++j)
- free (filenames[j]);
- free (filenames);
- oconfig_free (root);
- return (NULL);
+ if (temp == NULL)
+ {
+ /* An error should already have been reported. */
+ sfree (name);
+ continue;
}
cf_ci_append_children (root, temp);
}
cf_ci_append_children (root, temp);
@@
-702,11
+708,10
@@
static oconfig_item_t *cf_read_generic (const char *path, int depth)
if (status != 0)
{
char errbuf[1024];
if (status != 0)
{
char errbuf[1024];
-
ERROR
("configfile: stat (%s) failed: %s",
+
WARNING
("configfile: stat (%s) failed: %s",
path_ptr,
sstrerror (errno, errbuf, sizeof (errbuf)));
path_ptr,
sstrerror (errno, errbuf, sizeof (errbuf)));
- oconfig_free (root);
- return (NULL);
+ continue;
}
if (S_ISREG (statbuf.st_mode))
}
if (S_ISREG (statbuf.st_mode))
@@
-715,7
+720,7
@@
static oconfig_item_t *cf_read_generic (const char *path, int depth)
temp = cf_read_dir (path_ptr, depth);
else
{
temp = cf_read_dir (path_ptr, depth);
else
{
-
ERROR
("configfile: %s is neither a file nor a "
+
WARNING
("configfile: %s is neither a file nor a "
"directory.", path);
continue;
}
"directory.", path);
continue;
}
@@
-732,6
+737,12
@@
static oconfig_item_t *cf_read_generic (const char *path, int depth)
wordfree (&we);
wordfree (&we);
+ if (root->children == NULL)
+ {
+ oconfig_free (root);
+ return (NULL);
+ }
+
return (root);
} /* oconfig_item_t *cf_read_generic */
/* #endif HAVE_WORDEXP_H */
return (root);
} /* oconfig_item_t *cf_read_generic */
/* #endif HAVE_WORDEXP_H */