]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer-smtp: free mpm contexts on shutdown
authorJustin Viiret <justin.viiret@intel.com>
Wed, 25 May 2016 01:47:24 +0000 (11:47 +1000)
committerVictor Julien <victor@inliniac.net>
Fri, 27 May 2016 13:13:54 +0000 (15:13 +0200)
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.

src/app-layer-parser.c
src/app-layer-smtp.c
src/app-layer-smtp.h

index 018214cc0723cae1bb24f4090f0bf5888fe3d628..14942d16793999562cf5dcd83489e03b83fc03c5 100644 (file)
@@ -191,6 +191,8 @@ int AppLayerParserDeSetup(void)
 {
     SCEnter();
 
+    SMTPParserCleanup();
+
     SCReturnInt(0);
 }
 
index 98870a8e244729b28b9690d7cd0981a933dda15a..b68fa17fff448128b7335383e0bc565865fd3501 100644 (file)
@@ -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
index 1f925c625ed3e28a806046c043b16e74797603b4..9285f6217c584fdd1bd39d8528b272a7ad17c138 100644 (file)
@@ -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__ */