From: Justin Viiret Date: Wed, 25 May 2016 01:47:24 +0000 (+1000) Subject: app-layer-smtp: free mpm contexts on shutdown X-Git-Tag: suricata-3.1RC1~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a0dbc6f9f39d4527f4f927347196c9a757917dc;p=thirdparty%2Fsuricata.git app-layer-smtp: free mpm contexts on shutdown Adds a cleanup function for the SMTP parser that destroys the MPM context and MPM thread context it uses. Also marks smtp_mpm_thread_ctx static. --- diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 018214cc07..14942d1679 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -191,6 +191,8 @@ int AppLayerParserDeSetup(void) { SCEnter(); + SMTPParserCleanup(); + SCReturnInt(0); } diff --git a/src/app-layer-smtp.c b/src/app-layer-smtp.c index 98870a8e24..b68fa17fff 100644 --- a/src/app-layer-smtp.c +++ b/src/app-layer-smtp.c @@ -155,7 +155,7 @@ SCEnumCharMap smtp_decoder_event_table[ ] = { #define SMTP_MPM DEFAULT_MPM static MpmCtx *smtp_mpm_ctx = NULL; -MpmThreadCtx *smtp_mpm_thread_ctx; +static MpmThreadCtx *smtp_mpm_thread_ctx = NULL; /* smtp reply codes. If an entry is made here, please make a simultaneous * entry in smtp_reply_map */ @@ -1456,6 +1456,18 @@ static void SMTPSetMpmState(void) MpmInitThreadCtx(smtp_mpm_thread_ctx, SMTP_MPM); } +static void SMTPFreeMpmState(void) +{ + if (smtp_mpm_thread_ctx != NULL) { + mpm_table[SMTP_MPM].DestroyThreadCtx(smtp_mpm_ctx, smtp_mpm_thread_ctx); + smtp_mpm_thread_ctx = NULL; + } + if (smtp_mpm_ctx != NULL) { + mpm_table[SMTP_MPM].DestroyCtx(smtp_mpm_ctx); + smtp_mpm_ctx = NULL; + } +} + int SMTPStateGetEventInfo(const char *event_name, int *event_id, AppLayerEventType *event_type) { @@ -1677,6 +1689,14 @@ void RegisterSMTPParsers(void) return; } +/** + * \brief Free memory allocated for global SMTP parser state. + */ +void SMTPParserCleanup(void) +{ + SMTPFreeMpmState(); +} + /***************************************Unittests******************************/ #ifdef UNITTESTS diff --git a/src/app-layer-smtp.h b/src/app-layer-smtp.h index 1f925c625e..9285f6217c 100644 --- a/src/app-layer-smtp.h +++ b/src/app-layer-smtp.h @@ -169,6 +169,7 @@ extern SMTPConfig smtp_config; int SMTPProcessDataChunk(const uint8_t *chunk, uint32_t len, MimeDecParseState *state); void *SMTPStateAlloc(void); void RegisterSMTPParsers(void); +void SMTPParserCleanup(void); void SMTPParserRegisterTests(void); #endif /* __APP_LAYER_SMTP_H__ */