From: Victor Julien Date: Tue, 14 May 2013 11:14:37 +0000 (+0200) Subject: pool: add error msgs and improve memory layout X-Git-Tag: suricata-2.0beta1~59 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=016d03bdaf597c425433d501ab321330e438fb9c;p=thirdparty%2Fsuricata.git pool: add error msgs and improve memory layout --- diff --git a/src/util-pool.c b/src/util-pool.c index a8a372bba2..0a22762ee7 100644 --- a/src/util-pool.c +++ b/src/util-pool.c @@ -84,17 +84,25 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * { Pool *p = NULL; - if (size != 0 && prealloc_size > size) + if (size != 0 && prealloc_size > size) { + SCLogError(SC_ERR_POOL_INIT, "size error"); goto error; - if (size != 0 && elt_size == 0) + } + if (size != 0 && elt_size == 0) { + SCLogError(SC_ERR_POOL_INIT, "size != 0 && elt_size == 0"); goto error; - if (elt_size && Free) + } + if (elt_size && Free) { + SCLogError(SC_ERR_POOL_INIT, "elt_size && Free"); goto error; + } /* setup the filter */ p = SCMalloc(sizeof(Pool)); - if (unlikely(p == NULL)) + if (unlikely(p == NULL)) { + SCLogError(SC_ERR_POOL_INIT, "alloc error"); goto error; + } memset(p,0,sizeof(Pool)); @@ -116,8 +124,10 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * uint32_t u32 = 0; if (size > 0) { PoolBucket *pb = SCCalloc(size, sizeof(PoolBucket)); - if (unlikely(pb == NULL)) + if (unlikely(pb == NULL)) { + SCLogError(SC_ERR_POOL_INIT, "alloc error"); goto error; + } p->pb_buffer = pb; memset(pb, 0, size * sizeof(PoolBucket)); for (u32 = 0; u32 < size; u32++) { @@ -133,15 +143,19 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * if (size > 0) { p->data_buffer = SCCalloc(prealloc_size, elt_size); /* FIXME better goto */ - if (p->data_buffer == NULL) + if (p->data_buffer == NULL) { + SCLogError(SC_ERR_POOL_INIT, "alloc error"); goto error; + } } /* prealloc the buckets and requeue them to the alloc list */ for (u32 = 0; u32 < prealloc_size; u32++) { if (size == 0) { /* unlimited */ PoolBucket *pb = SCMalloc(sizeof(PoolBucket)); - if (unlikely(pb == NULL)) + if (unlikely(pb == NULL)) { + SCLogError(SC_ERR_POOL_INIT, "alloc error"); goto error; + } memset(pb, 0, sizeof(PoolBucket)); @@ -151,10 +165,12 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * pb->data = SCMalloc(p->elt_size); } if (pb->data == NULL) { + SCLogError(SC_ERR_POOL_INIT, "alloc error"); SCFree(pb); goto error; } 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) @@ -174,11 +190,14 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * p->alloc_list_size++; } else { PoolBucket *pb = p->empty_list; - if (pb == NULL) + if (pb == NULL) { + SCLogError(SC_ERR_POOL_INIT, "alloc error"); goto error; + } 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); goto error; diff --git a/src/util-pool.h b/src/util-pool.h index 72dc85883d..83fc8fa477 100644 --- a/src/util-pool.h +++ b/src/util-pool.h @@ -45,16 +45,16 @@ typedef struct Pool_ { uint32_t preallocated; uint32_t allocated; + uint32_t alloc_list_size; PoolBucket *alloc_list; PoolBucket *alloc_list_tail; - uint32_t alloc_list_size; PoolBucket *empty_list; uint32_t empty_list_size; - PoolBucket *pb_buffer; - void *data_buffer; int data_buffer_size; + void *data_buffer; + PoolBucket *pb_buffer; void *(*Alloc)(); int (*Init)(void *, void *);