diff --git a/src/flow-hash.c b/src/flow-hash.c index 3fb38dd846..8f806ea449 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -340,7 +340,7 @@ static Flow *FlowGetNew(Packet *p) { } /* now see if we can alloc a new flow */ - f = FlowAllocDirect(); + f = FlowAlloc(); if (f == NULL) { return NULL; } diff --git a/src/flow-util.c b/src/flow-util.c index a4cf654d39..fd330916fc 100644 --- a/src/flow-util.c +++ b/src/flow-util.c @@ -39,46 +39,12 @@ /* Counter of flows that reached memcap capability */ uint32_t directflows = 0; -/* Allocate a flow without checking memcap */ -Flow *FlowAllocDirect(void) -{ - Flow *f; - - SCMutexLock(&flow_memuse_mutex); - /* We allow to alloc even if memcap is reached (but later we - * will clean up some flows */ - f = SCMalloc(sizeof(Flow)); - if (f == NULL) { - SCMutexUnlock(&flow_memuse_mutex); - return NULL; - } - directflows++; - - flow_memuse += sizeof(Flow); - SCMutexUnlock(&flow_memuse_mutex); - //FlowPrintQueueInfo(); - - SCMutexInit(&f->m, NULL); - f->lnext = NULL; - f->lprev = NULL; - f->hnext = NULL; - f->hprev = NULL; - - f->flowvar = NULL; - - return f; -} - /* Allocate a flow */ Flow *FlowAlloc(void) { Flow *f; SCMutexLock(&flow_memuse_mutex); - if (flow_memuse + sizeof(Flow) > flow_config.memcap) { - SCMutexUnlock(&flow_memuse_mutex); - return NULL; - } f = SCMalloc(sizeof(Flow)); if (f == NULL) { SCMutexUnlock(&flow_memuse_mutex); diff --git a/src/flow.c b/src/flow.c index 06ba5a47ee..7091213f6f 100644 --- a/src/flow.c +++ b/src/flow.c @@ -792,8 +792,15 @@ void FlowInitConfig (char quiet) /* pre allocate flows */ for (i = 0; i < flow_config.prealloc; i++) { + if (flow_memuse + sizeof(Flow) > flow_config.memcap) { + SCMutexUnlock(&flow_memuse_mutex); + printf("ERROR: FlowAlloc failed (max flow memcap reached): %s\n", strerror(errno)); + exit(1); + } + Flow *f = FlowAlloc(); if (f == NULL) { + SCMutexUnlock(&flow_memuse_mutex); printf("ERROR: FlowAlloc failed: %s\n", strerror(errno)); exit(1); }