From 5b56d324c4e75587c3f79589612733af913a4b6c Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 13 May 2017 01:10:20 +0200 Subject: [PATCH] app-layer: optimize many-tx case --- src/app-layer-parser.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 2eced26486..9fe63e08eb 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -147,6 +147,8 @@ struct AppLayerParserState_ { * unless we have the entire transaction. */ uint64_t log_id; + uint64_t min_id; + /* Used to store decoder events. */ AppLayerDecoderEvents *decoder_events; }; @@ -748,7 +750,7 @@ uint64_t AppLayerTransactionGetActiveLogOnly(Flow *f, uint8_t flags) /* logger is disabled, return highest 'complete' tx id */ uint64_t total_txs = AppLayerParserGetTxCnt(f, f->alstate); - uint64_t idx = AppLayerParserGetTransactionInspectId(f->alparser, flags); + uint64_t idx = f->alparser->min_id; int state_done_progress = AppLayerParserGetStateProgressCompletionStatus(f->alproto, flags); void *tx; int state_progress; @@ -806,8 +808,22 @@ static void AppLayerParserTransactionsCleanup(Flow *f) uint64_t min = MIN(tx_id_ts, tx_id_tc); if (min > 0) { + uint64_t x = f->alparser->min_id; + for ( ; x < min - 1; x++) { + void *tx = AppLayerParserGetTx(f->proto, f->alproto, f->alstate, x); + if (tx != 0) { + SCLogDebug("while freeing %"PRIu64", also free TX at %"PRIu64, min - 1, x); + p->StateTransactionFree(f->alstate, x); + } + } + SCLogDebug("freeing %"PRIu64" %p", min - 1, p->StateTransactionFree); - p->StateTransactionFree(f->alstate, min - 1); + + if ((AppLayerParserGetTx(f->proto, f->alproto, f->alstate, min - 1))) { + p->StateTransactionFree(f->alstate, min - 1); + } + f->alparser->min_id = min - 1; + SCLogDebug("f->alparser->min_id %"PRIu64, f->alparser->min_id); } } -- 2.47.2