X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_cache.c;h=c4cef28b204978dd34f24af6aadad64d363b826f;hb=65c20e41cfad6e7ab024983f561835fd347124ce;hp=fe22f211bceafac758ad5734672526cc86df640c;hpb=f2389f97fbec15f49dcd1d9b06b3b6bbd0837e8a;p=collectd.git diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index fe22f211..c4cef28b 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -193,11 +193,13 @@ static int uc_insert (const data_set_t *ds, const value_list_t *vl, / CDTIME_T_TO_DOUBLE (vl->interval); ce->values_raw[i].absolute = vl->values[i].absolute; break; - + default: /* This shouldn't happen. */ ERROR ("uc_insert: Don't know how to handle data source type %i.", ds->ds[i].type); + sfree (key_copy); + cache_free (ce); return (-1); } /* switch (ds->ds[i].type) */ } /* for (i) */ @@ -303,7 +305,13 @@ int uc_check_timeout (void) pthread_mutex_unlock (&cache_lock); if (keys_len == 0) + { + /* realloc() may have been called for these. */ + sfree (keys); + sfree (keys_time); + sfree (keys_interval); return (0); + } /* Call the "missing" callback for each value. Do this before removing the * value from the cache, so that callbacks can still access the data stored, @@ -322,7 +330,6 @@ int uc_check_timeout (void) if (status != 0) { ERROR ("uc_check_timeout: parse_identifier_vl (\"%s\") failed.", keys[i]); - cache_free (ce); continue; } @@ -570,7 +577,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); @@ -648,12 +655,13 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number) if (status != 0) { size_t i; - + for (i = 0; i < number; i++) { sfree (names[i]); } sfree (names); + sfree (times); return (-1); } @@ -661,6 +669,8 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number) *ret_names = names; if (ret_times != NULL) *ret_times = times; + else + sfree (times); *ret_number = number; return (0); @@ -699,7 +709,7 @@ int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state) if (FORMAT_VL (name, sizeof (name), vl) != 0) { - ERROR ("uc_get_state: FORMAT_VL failed."); + ERROR ("uc_set_state: FORMAT_VL failed."); return (STATE_ERROR); } @@ -744,7 +754,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); @@ -808,7 +817,7 @@ int uc_get_hits (const data_set_t *ds, const value_list_t *vl) if (FORMAT_VL (name, sizeof (name), vl) != 0) { - ERROR ("uc_get_state: FORMAT_VL failed."); + ERROR ("uc_get_hits: FORMAT_VL failed."); return (STATE_ERROR); } @@ -833,7 +842,7 @@ int uc_set_hits (const data_set_t *ds, const value_list_t *vl, int hits) if (FORMAT_VL (name, sizeof (name), vl) != 0) { - ERROR ("uc_get_state: FORMAT_VL failed."); + ERROR ("uc_set_hits: FORMAT_VL failed."); return (STATE_ERROR); } @@ -859,7 +868,7 @@ int uc_inc_hits (const data_set_t *ds, const value_list_t *vl, int step) if (FORMAT_VL (name, sizeof (name), vl) != 0) { - ERROR ("uc_get_state: FORMAT_VL failed."); + ERROR ("uc_inc_hits: FORMAT_VL failed."); return (STATE_ERROR); }