From 23569b18765fcfa10897b6fa92d1871a9cb31986 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 28 Oct 2015 01:05:31 +0100 Subject: [PATCH] mx_util: Fix mx_strvec_length cache bug When freeing old strvec and allocation new strvec the cache entry is not cleared. Fix: reset cache entry for new strvecs if the new strvec is currently cached. Reported-by: Donald Buczek --- mx_util.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mx_util.c b/mx_util.c index e2b488ce..f2a74db2 100644 --- a/mx_util.c +++ b/mx_util.c @@ -18,6 +18,8 @@ #include "mx_log.h" #include "mx_util.h" +static inline size_t mx_strvec_length_cache(char **strvec, int32_t len); + static inline int _mx_strbeginswith(char *str, const char *start, char **endptr, short ignore_case) { size_t len; @@ -930,8 +932,15 @@ void *mx_calloc_forever_sec(size_t nmemb, size_t size, unsigned int time) char **mx_strvec_new(void) { char **strvec; + size_t len; strvec = calloc(sizeof(*strvec), 1); + if (!strvec) + return NULL; + + len = mx_strvec_length_cache(strvec, -1); + if (len != -1) + mx_strvec_length_cache(strvec, 0); return strvec; }