]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pool: improve error handling 59/head
authorEric Leblond <eric@regit.org>
Thu, 6 Sep 2012 11:57:20 +0000 (13:57 +0200)
committerEric Leblond <eric@regit.org>
Thu, 6 Sep 2012 12:01:57 +0000 (14:01 +0200)
Error handling during Pool creation was not perfect as a PoolBucket
could leak.

src/util-pool.c

index e997dc1728c6b27e27004b34220ff45b798d5c60..6a305ac8ddc5241752e6af22413e3a6b5f53fadd 100644 (file)
@@ -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;