X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_cache.c;h=9328d7ad9b413218c71b36920df36029c426d0c3;hb=21058a13ed34ade6d2de0f54e4216b255d033af1;hp=e2c64261d34aa363aacb41c315fd152204397445;hpb=0d9a0eb065fda6f89fc597e760ae56edd47337d9;p=collectd.git diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index e2c64261..9328d7ad 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 (); @@ -264,7 +263,7 @@ int uc_check_timeout (void) continue; /* If entry has not been updated, add to `keys' array */ - tmp = (char **) realloc ((void *) keys, + tmp = realloc ((void *) keys, (keys_len + 1) * sizeof (char *)); if (tmp == NULL) { @@ -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."); @@ -559,7 +558,7 @@ gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl) return (ret); } /* gauge_t *uc_get_rate */ -size_t uc_get_size() { +size_t uc_get_size (void) { size_t size_arrays = 0; pthread_mutex_lock (&cache_lock); @@ -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);