diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 250500a38c..4c6beea200 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -20,7 +20,19 @@ #include "util-debug.h" +static uint16_t app_layer_sid = 0; +static AppLayerProto al_proto_table[ALPROTO_MAX]; + +#define MAX_PARSERS 100 +static AppLayerParserTableElement al_parser_table[MAX_PARSERS]; +static uint16_t al_max_parsers = 0; /* incremented for every registered parser */ + static Pool *al_result_pool = NULL; +static SCMutex al_result_pool_mutex = PTHREAD_MUTEX_INITIALIZER; +#ifdef DEBUG +static uint32_t al_result_pool_elmts = 0; +#endif /* DEBUG */ + /** \brief Alloc a AppLayerParserResultElmt func for the pool */ static void *AlpResultElmtPoolAlloc(void *null) @@ -32,6 +44,11 @@ static void *AlpResultElmtPoolAlloc(void *null) } memset(e, 0, sizeof(AppLayerParserResultElmt)); + +#ifdef DEBUG + al_result_pool_elmts++; + SCLogDebug("al_result_pool_elmts %"PRIu32"", al_result_pool_elmts); +#endif /* DEBUG */ return e; } @@ -44,11 +61,19 @@ static void AlpResultElmtPoolFree(void *e) free(re->data_ptr); } free(re); + +#ifdef DEBUG + al_result_pool_elmts--; + SCLogDebug("al_result_pool_elmts %"PRIu32"", al_result_pool_elmts); +#endif /* DEBUG */ } static AppLayerParserResultElmt *AlpGetResultElmt(void) { + SCMutexLock(&al_result_pool_mutex); AppLayerParserResultElmt *e = (AppLayerParserResultElmt *)PoolGet(al_result_pool); + SCMutexUnlock(&al_result_pool_mutex); + if (e == NULL) { return NULL; } @@ -67,7 +92,9 @@ static void AlpReturnResultElmt(AppLayerParserResultElmt *e) e->data_len = 0; e->next = NULL; + SCMutexLock(&al_result_pool_mutex); PoolReturn(al_result_pool, (void *)e); + SCMutexUnlock(&al_result_pool_mutex); } static void AlpAppendResultElmt(AppLayerParserResult *r, AppLayerParserResultElmt *e) @@ -426,13 +453,6 @@ int AlpParseFieldByDelimiter(AppLayerParserResult *output, AppLayerParserState * SCReturnInt(0); } -static uint16_t app_layer_sid = 0; -static AppLayerProto al_proto_table[ALPROTO_MAX]; - -#define MAX_PARSERS 100 -static AppLayerParserTableElement al_parser_table[MAX_PARSERS]; -static uint16_t al_max_parsers = 0; /* incremented for every registered parser */ - /** \brief Get the Parsers id for storing the parser state. * * \retval Parser subsys id diff --git a/src/flow.c b/src/flow.c index 907a65e9bc..16e6160ceb 100644 --- a/src/flow.c +++ b/src/flow.c @@ -203,9 +203,9 @@ static int FlowPrune (FlowQueue *q, struct timeval *ts) /* remove from the hash */ if (f->hprev) - f->hprev->hnext = f->hnext; + f->hprev->hnext = f->hnext; if (f->hnext) - f->hnext->hprev = f->hprev; + f->hnext->hprev = f->hprev; if (f->fb->f == f) f->fb->f = f->hnext; @@ -249,9 +249,7 @@ static int FlowUpdateSpareFlows(void) { uint32_t toalloc = 0, tofree = 0, len; SCMutexLock(&flow_spare_q.mutex_q); - len = flow_spare_q.len; - SCMutexUnlock(&flow_spare_q.mutex_q); if (len < flow_config.prealloc) { @@ -272,6 +270,7 @@ static int FlowUpdateSpareFlows(void) { uint32_t i; for (i = 0; i < tofree; i++) { + /* FlowDequeue locks the queue */ Flow *f = FlowDequeue(&flow_spare_q); if (f == NULL) return 1; diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index 951d7a919d..9476f56dd2 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -75,7 +75,8 @@ void *TcpSegmentPoolAlloc(void *payload_len) { #ifdef DEBUG SCMutexLock(&segment_pool_memuse_mutex); segment_pool_memuse += seg->payload_len; - segment_pool_memcnt ++; + segment_pool_memcnt++; + SCLogDebug("segment_pool_memcnt %"PRIu64"", segment_pool_memcnt); SCMutexUnlock(&segment_pool_memuse_mutex); #endif return seg; @@ -89,6 +90,14 @@ void TcpSegmentPoolFree(void *ptr) { TcpSegment *seg = (TcpSegment *) ptr; free(seg->payload); free(seg); + +#ifdef DEBUG + SCMutexLock(&segment_pool_memuse_mutex); + segment_pool_memuse -= seg->payload_len; + segment_pool_memcnt--; + SCLogDebug("segment_pool_memcnt %"PRIu64"", segment_pool_memcnt); + SCMutexUnlock(&segment_pool_memuse_mutex); +#endif return; }