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.
pull/2115/head
Justin Viiret 9 years ago committed by Victor Julien
parent d807bf4e8a
commit 7a0dbc6f9f

@ -191,6 +191,8 @@ int AppLayerParserDeSetup(void)
{
SCEnter();
SMTPParserCleanup();
SCReturnInt(0);
}

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

@ -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__ */

Loading…
Cancel
Save