Properly lock app layer result pool and add some debugging code for memory tracking.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent 4284276b11
commit cae8e06cb9

@ -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

@ -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;

@ -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;
}

Loading…
Cancel
Save