X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_cache.c;h=7eae1c7ed5121e6cb01f15f10336392911ade236;hb=d404a0c4f97ef047c2add2e27f2424f01bc45ad7;hp=539545ac607b988b86e4b995fa97d86b89d672fc;hpb=b9390e53e68f70cac2a6b5122214a86bfb51ae65;p=collectd.git diff --git a/src/utils_cache.c b/src/utils_cache.c index 539545ac..7eae1c7e 100644 --- a/src/utils_cache.c +++ b/src/utils_cache.c @@ -296,7 +296,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, @@ -315,7 +321,6 @@ int uc_check_timeout (void) if (status != 0) { ERROR ("uc_check_timeout: parse_identifier_vl (\"%s\") failed.", keys[i]); - cache_free (ce); continue; } @@ -574,18 +579,6 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number) size_t number = 0; size_t size_arrays = 0; - /* Increment size for the 2 arrays of values - * Because realloc is time consuming, it's better to - * realloc by blocks and not by units. - * To see the difference, set this value to 1. - * - * To change this value at compile time: - * ./configure CPPFLAGS="-DLISTVAL_INCREASE=102400" - */ -#ifndef LISTVAL_INCREASE -# define LISTVAL_INCREASE 1024 -#endif - int status = 0; if ((ret_names == NULL) || (ret_number == NULL)) @@ -598,7 +591,7 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number) { /* Handle the "no values" case here, to avoid the error message when * calloc() returns NULL. */ - pthread_mutex_lock (&cache_lock); + pthread_mutex_unlock (&cache_lock); return (0); } @@ -609,7 +602,7 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number) ERROR ("uc_get_names: calloc failed."); sfree (names); sfree (times); - pthread_mutex_lock (&cache_lock); + pthread_mutex_unlock (&cache_lock); return (ENOMEM); } @@ -643,12 +636,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); } @@ -656,6 +650,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);