From: Eric Leblond Date: Thu, 6 Sep 2012 11:57:20 +0000 (+0200) Subject: pool: improve error handling X-Git-Tag: suricata-1.4beta1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F59%2Fhead;p=thirdparty%2Fsuricata.git pool: improve error handling Error handling during Pool creation was not perfect as a PoolBucket could leak. --- diff --git a/src/util-pool.c b/src/util-pool.c index e997dc1728..6a305ac8dd 100644 --- a/src/util-pool.c +++ b/src/util-pool.c @@ -142,10 +142,17 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * } else { pb->data = SCMalloc(p->elt_size); } - if (pb->data == NULL) + if (pb->data == NULL) { + SCFree(pb); goto error; - if (p->Init(pb->data, p->InitData) != 1) + } + if (p->Init(pb->data, p->InitData) != 1) { + if (p->Free) + p->Free(pb->data); + SCFree(pb->data); + SCFree(pb); goto error; + } p->allocated++; pb->next = p->alloc_list; @@ -156,12 +163,16 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * if (pb == NULL) goto error; + pb->data = (char *)p->data_buffer + u32 * elt_size; + if (p->Init(pb->data, p->InitData) != 1) { + if (p->Free) + p->Free(pb->data); + goto error; + } + p->empty_list = pb->next; p->empty_list_size--; - pb->data = (char *)p->data_buffer + u32 * elt_size; - if (p->Init(pb->data, p->InitData) != 1) - goto error; p->allocated++; pb->next = p->alloc_list;