From: Florian Forster Date: Fri, 19 Jun 2015 05:05:22 +0000 (+0200) Subject: src/utils_cache.c: Fix two memory leaks. X-Git-Tag: collectd-5.5.1~68^2~36 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=813fadc54fbf0c9b948163851e9791a1ace716ae;p=collectd.git src/utils_cache.c: Fix two memory leaks. * Free "times" pointer if it is not returned to the user. * Free (re)alloc'ed pointers when strdup() fails. --- diff --git a/src/utils_cache.c b/src/utils_cache.c index e77f9942..dc0ff0df 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, @@ -643,6 +649,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);