From: Victor Julien Date: Fri, 21 Sep 2012 12:17:42 +0000 (+0200) Subject: pool: only alloc one large block if it will actually be used. X-Git-Tag: suricata-1.4beta2~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f962e3de296344e591075fae9acd624dac5dabef;p=thirdparty%2Fsuricata.git pool: only alloc one large block if it will actually be used. --- diff --git a/src/util-pool.c b/src/util-pool.c index 23d4927a51..7e25ea58b6 100644 --- a/src/util-pool.c +++ b/src/util-pool.c @@ -85,6 +85,8 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * if (size != 0 && prealloc_size > size) goto error; + if (size != 0 && elt_size == 0) + goto error; /* setup the filter */ p = SCMalloc(sizeof(Pool)); @@ -124,10 +126,12 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size, void * } } - p->data_buffer = SCCalloc(prealloc_size, elt_size); - /* FIXME better goto */ - if (p->data_buffer == NULL) - goto error; + if (size > 0) { + p->data_buffer = SCCalloc(prealloc_size, elt_size); + /* FIXME better goto */ + if (p->data_buffer == NULL) + goto error; + } /* prealloc the buckets and requeue them to the alloc list */ for (u32 = 0; u32 < prealloc_size; u32++) { if (size == 0) { /* unlimited */