From: Bryon Gloden, CISSPĀ® Date: Tue, 2 Aug 2016 21:19:19 +0000 (-0400) Subject: Update acism_create.c X-Git-Tag: 1.3.2~64^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a7abc8348801f8bc2f802447c109083b9e199806;p=rspamd.git Update acism_create.c Passing one pointer into realloc() and assigning the result directly into that same pointer variable can cause a memory leak if the reallocation fails, because the original allocation will still exist. The correct way to do this is to use a temporary pointer variable. Credit: http://stackoverflow.com/a/11548901 Found by https://github.com/bryongloden/cppcheck --- diff --git a/contrib/aho-corasick/acism_create.c b/contrib/aho-corasick/acism_create.c index b1d9b51e3..a6d007fd7 100644 --- a/contrib/aho-corasick/acism_create.c +++ b/contrib/aho-corasick/acism_create.c @@ -323,9 +323,15 @@ interleave(TNODE *troot, int nnodes, int nsyms, TNODE **v1, TNODE **v2) if (last_trans < last) { last_trans = last; if (last + nsyms >= usev_size) { - usev = realloc(usev, usev_size << 1); - memset(usev + usev_size, 0, usev_size); - usev_size <<= 1; + char *tmp = realloc(usev, usev_size << 1); + if (tmp != NULL) { + usev = tmp; + memset(usev + usev_size, 0, usev_size); + usev_size <<= 1; + } else { + free(usev); + /* And handle error */ + } } } }