X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_cache.c;h=b5b059c0392e8f7b357c4bdab114eeb3f4e12b77;hb=8361c1e963f9184c3c4d87197fd6996d667cdb3f;hp=7054ae4fa9a9f83caba9b4a2e6d01c53e01d9a60;hpb=eb2f3a4bdc78e1e2c4191b4e08d75d5eeea8be0e;p=collectd.git diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index 7054ae4f..b5b059c0 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -83,13 +83,12 @@ static cache_entry_t *cache_alloc (size_t values_num) { cache_entry_t *ce; - ce = (cache_entry_t *) malloc (sizeof (cache_entry_t)); + ce = calloc (1, sizeof (*ce)); if (ce == NULL) { - ERROR ("utils_cache: cache_alloc: malloc failed."); + ERROR ("utils_cache: cache_alloc: calloc failed."); return (NULL); } - memset (ce, '\0', sizeof (cache_entry_t)); ce->values_num = values_num; ce->values_gauge = calloc (values_num, sizeof (*ce->values_gauge)); @@ -247,7 +246,7 @@ int uc_check_timeout (void) int status; int i; - + pthread_mutex_lock (&cache_lock); now = cdtime (); @@ -499,7 +498,7 @@ int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_val else { ret_num = ce->values_num; - ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t)); + ret = malloc (ret_num * sizeof (*ret)); if (ret == NULL) { ERROR ("utils_cache: uc_get_rate_by_name: malloc failed."); @@ -736,7 +735,6 @@ int uc_get_history_by_name (const char *name, if (ce->history_length < num_steps) { gauge_t *tmp; - size_t i; tmp = realloc (ce->history, sizeof (*ce->history) * num_steps * ce->values_num);