From 5599e1aa8ec62788f4a75f0944eb58bbab7035df Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Sat, 12 Apr 2014 20:52:01 +0300 Subject: [PATCH] Store tmp to tokv in for loop, so we can free it if something fails. --- lib/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/filter.c b/lib/filter.c index 204eac1..ad1b937 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -57,8 +57,8 @@ static char* _bmFilterTokenize(bmMenu *menu, char ***outTokv, unsigned int *outT size_t pos = 0, next; unsigned int tokc = 0, tokn = 0; char *s = buffer, **tmp = NULL; - while ((pos = _bmStripToken(s, " ", &next)) > 0) { - if (++tokc > tokn && !(tmp = realloc(tmp, ++tokn * sizeof(char*)))) + for (; (pos = _bmStripToken(s, " ", &next)) > 0; tokv = tmp) { + if (++tokc > tokn && !(tmp = realloc(tokv, ++tokn * sizeof(char*)))) goto fail; tmp[tokc - 1] = s;