]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pool: update internal counters at the proper time
authorVictor Julien <victor@inliniac.net>
Wed, 22 Jan 2014 14:32:18 +0000 (15:32 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 22 Jan 2014 15:49:02 +0000 (16:49 +0100)
Only update Pool::outstanding and Pool::allocated in PoolGet when
we are sure both Alloc and Init were successful.

src/util-pool.c

index b77b58306c8364876218c78a8f1038c5f232d471..40b005b1ac63a873d9ab5937138b6c5995026222 100644 (file)
@@ -301,21 +301,24 @@ void *PoolGet(Pool *p) {
         if (p->max_buckets == 0 || p->allocated < p->max_buckets) {
             void *pitem;
             SCLogDebug("max_buckets %"PRIu32"", p->max_buckets);
-            p->allocated++;
-
-            p->outstanding++;
-            if (p->outstanding > p->max_outstanding)
-                p->max_outstanding = p->outstanding;
 
             if (p->Alloc != NULL) {
                 pitem = p->Alloc();
             } else {
                 pitem = SCMalloc(p->elt_size);
             }
+
             if (pitem != NULL) {
                 if (p->Init(pitem, p->InitData) != 1)
                     SCReturnPtr(NULL, "void");
+
+                p->allocated++;
+
+                p->outstanding++;
+                if (p->outstanding > p->max_outstanding)
+                    p->max_outstanding = p->outstanding;
             }
+
             SCReturnPtr(pitem, "void");
         } else {
             SCReturnPtr(NULL, "void");