X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fconfigfile.c;h=1d81a6528c027e46c71de7fdc8c52c4ccf9ba9fc;hb=43aca8ed8b22a7a5a14f8c740948d6ce06efbc95;hp=8a7621d2b5fb912b02d64c8c9f86456d42dbea08;hpb=82c9b0daf5ff90d01f4a4371f11727cd613e4b01;p=collectd.git diff --git a/src/daemon/configfile.c b/src/daemon/configfile.c index 8a7621d2..1d81a652 100644 --- a/src/daemon/configfile.c +++ b/src/daemon/configfile.c @@ -257,7 +257,7 @@ static int dispatch_value_typesdb (oconfig_item_t *ci) static int dispatch_value_plugindir (oconfig_item_t *ci) { assert (strcasecmp (ci->key, "PluginDir") == 0); - + if (ci->values_num != 1) return (-1); if (ci->values[0].type != OCONFIG_TYPE_STRING) @@ -717,14 +717,13 @@ static oconfig_item_t *cf_read_dir (const char *dir, return (NULL); } - root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t)); + root = calloc (1, sizeof (*root)); if (root == NULL) { - ERROR ("configfile: malloc failed."); + ERROR ("configfile: calloc failed."); closedir (dh); return (NULL); } - memset (root, 0, sizeof (oconfig_item_t)); while ((de = readdir (dh)) != NULL) { @@ -835,13 +834,12 @@ static oconfig_item_t *cf_read_generic (const char *path, return (NULL); } - root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t)); + root = calloc (1, sizeof (*root)); if (root == NULL) { - ERROR ("configfile: malloc failed."); + ERROR ("configfile: calloc failed."); return (NULL); } - memset (root, '\0', sizeof (oconfig_item_t)); /* wordexp() might return a sorted list already. That's not * documented though, so let's make sure we get what we want. */ @@ -926,7 +924,7 @@ static oconfig_item_t *cf_read_generic (const char *path, } /* oconfig_item_t *cf_read_generic */ #endif /* !HAVE_WORDEXP_H */ -/* +/* * Public functions */ int global_option_set (const char *option, const char *value) @@ -969,7 +967,7 @@ const char *global_option_get (const char *option) if (i >= cf_global_options_num) return (NULL); - + return ((cf_global_options[i].value != NULL) ? cf_global_options[i].value : cf_global_options[i].def); @@ -1067,7 +1065,7 @@ void cf_register (const char *type, cf_unregister (type); /* This pointer will be free'd in `cf_unregister' */ - if ((cf_cb = (cf_callback_t *) malloc (sizeof (cf_callback_t))) == NULL) + if ((cf_cb = malloc (sizeof (*cf_cb))) == NULL) return; cf_cb->type = type; @@ -1084,7 +1082,7 @@ int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *)) { cf_complex_callback_t *new; - new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t)); + new = malloc (sizeof (*new)); if (new == NULL) return (-1);