Skip to content

Commit

Permalink
ipproto: improve cleanup
Browse files Browse the repository at this point in the history
To address:
~~Dr.M~~ Error #2: LEAK 16 direct bytes 0x08399688-0x08399698 + 2 indirect bytes
~~Dr.M~~ # 0 replace_malloc                      [/work/drmemory_package/common/alloc_replace.c:2292]
~~Dr.M~~ # 1 SigMatchAlloc                       [/home/victor/dev/oisf/src/detect-parse.c:201]
~~Dr.M~~ # 2 DetectIPProtoSetup                  [/home/victor/dev/oisf/src/detect-ipproto.c:523]
~~Dr.M~~ # 3 SigParseOptions                     [/home/victor/dev/oisf/src/detect-parse.c:510]
~~Dr.M~~ # 4 SigParseOptions                     [/home/victor/dev/oisf/src/detect-parse.c:523]
~~Dr.M~~ # 5 SigParse                            [/home/victor/dev/oisf/src/detect-parse.c:881]
~~Dr.M~~ # 6 SigInitHelper                       [/home/victor/dev/oisf/src/detect-parse.c:1309]
~~Dr.M~~ # 7 SigInit                             [/home/victor/dev/oisf/src/detect-parse.c:1456]
~~Dr.M~~ # 8 DetectEngineAppendSig               [/home/victor/dev/oisf/src/detect-parse.c:1728]
~~Dr.M~~ # 9 DetectLoadSigFile                   [/home/victor/dev/oisf/src/detect.c:334]
~~Dr.M~~ #10 SigLoadSignatures                   [/home/victor/dev/oisf/src/detect.c:422]
~~Dr.M~~ #11 LoadSignatures                      [/home/victor/dev/oisf/src/suricata.c:1706]
  • Loading branch information
victorjulien committed Sep 27, 2013
1 parent 1006d90 commit c43e078
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/detect-ipproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static pcre_extra *parse_regex_study;
static int DetectIPProtoSetup(DetectEngineCtx *, Signature *, char *);
static DetectIPProtoData *DetectIPProtoParse(const char *);
static void DetectIPProtoRegisterTests(void);
static void DetectIPProtoFree(void *);

void DetectIPProtoRegister(void)
{
Expand All @@ -69,7 +70,7 @@ void DetectIPProtoRegister(void)
sigmatch_table[DETECT_IPPROTO].url = "https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Header_keywords#ip_proto";
sigmatch_table[DETECT_IPPROTO].Match = NULL;
sigmatch_table[DETECT_IPPROTO].Setup = DetectIPProtoSetup;
sigmatch_table[DETECT_IPPROTO].Free = NULL;
sigmatch_table[DETECT_IPPROTO].Free = DetectIPProtoFree;
sigmatch_table[DETECT_IPPROTO].RegisterTests = DetectIPProtoRegisterTests;

parse_regex = pcre_compile(PARSE_REGEX, opts, &eb, &eo, NULL);
Expand All @@ -80,15 +81,18 @@ void DetectIPProtoRegister(void)
}

parse_regex_study = pcre_study(parse_regex, 0, &eb);
if (eb != NULL) {
SCLogError(SC_ERR_PCRE_STUDY, "pcre study failed: %s", eb);
if (parse_regex_study == NULL || eb != NULL) {
SCLogError(SC_ERR_PCRE_STUDY, "pcre study failed: %s", eb ? eb : "unknown");
goto error;
}

return;

error:
/* XXX */
if (parse_regex)
pcre_free(parse_regex);
if (parse_regex_study)
pcre_free_study(parse_regex_study);
return;
}

Expand Down Expand Up @@ -547,12 +551,20 @@ void DetectIPProtoRemoveAllSMs(Signature *s)
}
SigMatch *tmp_sm = sm->next;
SigMatchRemoveSMFromList(s, sm, DETECT_SM_LIST_MATCH);
SigMatchFree(sm);
sm = tmp_sm;
}

return;
}

static void DetectIPProtoFree(void *ptr) {
DetectIPProtoData *data = (DetectIPProtoData *)ptr;
if (data) {
SCFree(data);
}
}

/* UNITTESTS */
#ifdef UNITTESTS

Expand Down

0 comments on commit c43e078

Please sign in to comment.