]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pool: don't call Cleanup after failed Init 3898/head
authorVictor Julien <victor@inliniac.net>
Tue, 28 May 2019 13:45:37 +0000 (15:45 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 29 May 2019 13:34:36 +0000 (15:34 +0200)
Stream reassembly memcap is regulated by the Init and Cleanup
callbacks. If Init fails due to memcap reached, Cleanup had no
way of knowing and it would decrease the memcap even if it hadn't
been increased by Init. This could lead to too much memory use and
memcap counter underflow.

This patch fixes the issue by not calling Cleanup in this case. It's
fair to see a failed Init the responsibility of Init.

src/util-pool.c

index c88cc847cba94447d9020adaf5dcd3e53f9343be..ce55645d82a51fdecbfe95777d3fb5c6d82ddcd4 100644 (file)
@@ -171,8 +171,6 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
             }
             if (p->Init(pb->data, p->InitData) != 1) {
                 SCLogError(SC_ERR_POOL_INIT, "init error");
-                if (p->Cleanup)
-                    p->Cleanup(pb->data);
                 if (p->Free)
                     p->Free(pb->data);
                 else
@@ -195,8 +193,6 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
             pb->data = (char *)p->data_buffer + u32 * elt_size;
             if (p->Init(pb->data, p->InitData) != 1) {
                 SCLogError(SC_ERR_POOL_INIT, "init error");
-                if (p->Cleanup)
-                    p->Cleanup(pb->data);
                 pb->data = NULL;
                 goto error;
             }
@@ -303,8 +299,6 @@ void *PoolGet(Pool *p)
 
             if (pitem != NULL) {
                 if (p->Init(pitem, p->InitData) != 1) {
-                    if (p->Cleanup)
-                        p->Cleanup(pitem);
                     if (p->Free != NULL)
                         p->Free(pitem);
                     else