From: Victor Julien Date: Wed, 22 Jan 2014 14:32:18 +0000 (+0100) Subject: pool: update internal counters at the proper time X-Git-Tag: suricata-2.0rc1~168 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c9f9db7706afa76424693795fe95f2d1f03fbb7;p=thirdparty%2Fsuricata.git pool: update internal counters at the proper time Only update Pool::outstanding and Pool::allocated in PoolGet when we are sure both Alloc and Init were successful. --- diff --git a/src/util-pool.c b/src/util-pool.c index b77b58306c..40b005b1ac 100644 --- a/src/util-pool.c +++ b/src/util-pool.c @@ -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");