diff options
author | Bryon Gloden, CISSPĀ® <cissp@bryongloden.com> | 2016-08-02 17:19:19 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-02 17:19:19 -0400 |
commit | a7abc8348801f8bc2f802447c109083b9e199806 (patch) | |
tree | 87a6d2d19e8c7080144950629d60d64e9fb5f085 /contrib | |
parent | 0ef106e8a3a39c3dbd8e2cc5f24fff7e0e23ac40 (diff) | |
download | rspamd-a7abc8348801f8bc2f802447c109083b9e199806.tar.gz rspamd-a7abc8348801f8bc2f802447c109083b9e199806.zip |
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
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/aho-corasick/acism_create.c | 12 |
1 files changed, 9 insertions, 3 deletions
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 */ + } } } } |