]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pool: add error msgs and improve memory layout
authorVictor Julien <victor@inliniac.net>
Tue, 14 May 2013 11:14:37 +0000 (13:14 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 28 Jun 2013 09:05:40 +0000 (11:05 +0200)
src/util-pool.c
src/util-pool.h

index a8a372bba2800149607abce12c7cb2a3a9629f98..0a22762ee7a29074a5c8c9cc2d689660e8919f63 100644 (file)
@@ -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;
index 72dc85883d5c3302437288ddec158be4e3b59917..83fc8fa477d983b37fa52f683c38e51b67caa363 100644 (file)
@@ -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 *);