From 0fd9b0c4fac90cb58d6bb64bf4868b6e2a676a62 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 2 Jul 2013 12:51:42 +0200 Subject: [PATCH] HTP: free TX from transaction free API call --- src/app-layer-htp.c | 38 +++++++++++++------------------------- src/app-layer-htp.h | 1 - 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index a8e55618e4..7908806dea 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -303,17 +303,26 @@ void HTPStateFree(void *state) * \warning We cannot actually free the transactions here. It seems that * HTP only accepts freeing of transactions in the response callback. */ -void HTPStateTransactionFree(void *state, uint64_t id) { +static void HTPStateTransactionFree(void *state, uint64_t id) { SCEnter(); HtpState *s = (HtpState *)state; - s->transaction_done = id; SCLogDebug("state %p, id %"PRIu64, s, id); - /* we can't remove the actual transactions here */ + htp_tx_t *tx = HTPStateGetTx(s, id); + if (tx != NULL) { + /* This will remove obsolete body chunks */ + HtpTxUserData *htud = (HtpTxUserData *) htp_tx_get_user_data(tx); + if (htud != NULL) { + HtpBodyFree(&htud->request_body); + HtpBodyFree(&htud->response_body); + SCFree(htud); + htp_tx_set_user_data(tx, NULL); + } - SCReturn; + htp_tx_destroy(tx); + } } /** @@ -2001,27 +2010,6 @@ static int HTPCallbackResponse(htp_connp_t *connp) { } } - /* remove obsolete transactions */ - uint64_t idx; - for (idx = 0; idx < hstate->transaction_done; idx++) { - SCLogDebug("idx %"PRIuMAX, (uintmax_t)idx); - - htp_tx_t *tx = HTPStateGetTx(hstate, idx); - if (tx == NULL) - continue; - - /* This will remove obsolete body chunks */ - HtpTxUserData *htud = (HtpTxUserData *) htp_tx_get_user_data(tx); - if (htud != NULL) { - HtpBodyFree(&htud->request_body); - HtpBodyFree(&htud->response_body); - SCFree(htud); - htp_tx_set_user_data(tx, NULL); - } - - htp_tx_destroy(tx); - } - /* response done, do raw reassembly now to inspect state and stream * at the same time. */ AppLayerTriggerRawStreamReassembly(hstate->f); diff --git a/src/app-layer-htp.h b/src/app-layer-htp.h index f12a1e55c7..d9ea8352db 100644 --- a/src/app-layer-htp.h +++ b/src/app-layer-htp.h @@ -215,7 +215,6 @@ typedef struct HtpState_ { each connection */ Flow *f; /**< Needed to retrieve the original flow when usin HTPLib callbacks */ uint64_t transaction_cnt; - uint64_t transaction_done; uint64_t store_tx_id; FileContainer *files_ts; FileContainer *files_tc;