]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Improve memory cleanup for decoder-events
authorVictor Julien <victor@inliniac.net>
Fri, 27 Sep 2013 12:45:37 +0000 (14:45 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 27 Sep 2013 12:45:37 +0000 (14:45 +0200)
To address:

~~Dr.M~~ Error #1: LEAK 1 direct bytes 0x0892c108-0x0892c109 + 0 indirect bytes
~~Dr.M~~ # 0 replace_malloc                        [/work/drmemory_package/common/alloc_replace.c:2292]
~~Dr.M~~ # 1 DetectEngineEventParse                [/home/victor/dev/oisf/src/detect-engine-event.c:173]
~~Dr.M~~ # 2 _DetectEngineEventSetup               [/home/victor/dev/oisf/src/detect-engine-event.c:204]
~~Dr.M~~ # 3 DetectDecodeEventSetup                [/home/victor/dev/oisf/src/detect-engine-event.c:248]
~~Dr.M~~ # 4 SigParseOptions                       [/home/victor/dev/oisf/src/detect-parse.c:510]
~~Dr.M~~ # 5 SigParseOptions                       [/home/victor/dev/oisf/src/detect-parse.c:523]
~~Dr.M~~ # 6 SigParse                              [/home/victor/dev/oisf/src/detect-parse.c:881]
~~Dr.M~~ # 7 SigInitHelper                         [/home/victor/dev/oisf/src/detect-parse.c:1309]
~~Dr.M~~ # 8 SigInit                               [/home/victor/dev/oisf/src/detect-parse.c:1456]
~~Dr.M~~ # 9 DetectEngineAppendSig                 [/home/victor/dev/oisf/src/detect-parse.c:1728]
~~Dr.M~~ #10 DetectLoadSigFile                     [/home/victor/dev/oisf/src/detect.c:334]
~~Dr.M~~ #11 SigLoadSignatures                     [/home/victor/dev/oisf/src/detect.c:422]

src/detect-engine-event.c

index 3df86518372a0e530f77add0ad877ad922f4926e..daf77124a6516f80a2f9887291d2343449438575 100644 (file)
@@ -52,6 +52,7 @@ int DetectEngineEventMatch (ThreadVars *, DetectEngineThreadCtx *, Packet *, Sig
 static int DetectEngineEventSetup (DetectEngineCtx *, Signature *, char *);
 static int DetectDecodeEventSetup (DetectEngineCtx *, Signature *, char *);
 static int DetectStreamEventSetup (DetectEngineCtx *, Signature *, char *);
+static void DetectEngineEventFree (void *);
 void EngineEventRegisterTests(void);
 
 
@@ -62,19 +63,19 @@ void DetectEngineEventRegister (void) {
     sigmatch_table[DETECT_ENGINE_EVENT].name = "engine-event";
     sigmatch_table[DETECT_ENGINE_EVENT].Match = DetectEngineEventMatch;
     sigmatch_table[DETECT_ENGINE_EVENT].Setup = DetectEngineEventSetup;
-    sigmatch_table[DETECT_ENGINE_EVENT].Free  = NULL;
+    sigmatch_table[DETECT_ENGINE_EVENT].Free  = DetectEngineEventFree;
     sigmatch_table[DETECT_ENGINE_EVENT].RegisterTests = EngineEventRegisterTests;
 
     sigmatch_table[DETECT_DECODE_EVENT].name = "decode-event";
     sigmatch_table[DETECT_DECODE_EVENT].Match = DetectEngineEventMatch;
     sigmatch_table[DETECT_DECODE_EVENT].Setup = DetectDecodeEventSetup;
-    sigmatch_table[DETECT_DECODE_EVENT].Free  = NULL;
+    sigmatch_table[DETECT_DECODE_EVENT].Free  = DetectEngineEventFree;
     sigmatch_table[DETECT_DECODE_EVENT].flags |= SIGMATCH_DEONLY_COMPAT;
 
     sigmatch_table[DETECT_STREAM_EVENT].name = "stream-event";
     sigmatch_table[DETECT_STREAM_EVENT].Match = DetectEngineEventMatch;
     sigmatch_table[DETECT_STREAM_EVENT].Setup = DetectStreamEventSetup;
-    sigmatch_table[DETECT_STREAM_EVENT].Free  = NULL;
+    sigmatch_table[DETECT_STREAM_EVENT].Free  = DetectEngineEventFree;
 
     const char *eb;
     int eo;
@@ -234,8 +235,10 @@ static int DetectEngineEventSetup (DetectEngineCtx *de_ctx, Signature *s, char *
  *
  * \param de pointer to DetectEngineEventData
  */
-void DetectEngineEventFree(DetectEngineEventData *de) {
-    if(de) SCFree(de);
+static void DetectEngineEventFree(void *ptr) {
+    DetectEngineEventData *de = (DetectEngineEventData *)ptr;
+    if (de)
+        SCFree(de);
 }