Skip to content

Commit

Permalink
mx_util: Fix mx_strvec_length cache bug
Browse files Browse the repository at this point in the history
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 <buczek@molgen.mpg.de>
  • Loading branch information
mariux committed Oct 28, 2015
1 parent 279be59 commit 23569b1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mx_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 23569b1

Please sign in to comment.