From 97854cf4bb4661b01d6c1ff1b42000b4601da0cd Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 21 Aug 2009 00:04:56 +0200 Subject: [PATCH] Fixup some rule parser memleaks --- src/detect-content.c | 14 +++++++++++--- src/detect-flow.c | 7 ++++--- src/detect-flowbits.c | 11 ++++++++++- src/detect-pcre.c | 10 +++++----- src/detect.h | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/detect-content.c b/src/detect-content.c index 98f16690b5..e8f4bb677c 100644 --- a/src/detect-content.c +++ b/src/detect-content.c @@ -48,7 +48,7 @@ int DetectContentMatch (ThreadVars *, PatternMatcherThread *, Packet *, Signature *, SigMatch *); int DetectContentSetup (DetectEngineCtx *, Signature *, SigMatch *, char *); void DetectContentRegisterTests(void); -void DetectContentFree(DetectContentData *); +void DetectContentFree(void *); uint8_t nocasetable[256]; #define _nc(c) nocasetable[(c)] @@ -57,7 +57,7 @@ void DetectContentRegister (void) { sigmatch_table[DETECT_CONTENT].name = "content"; sigmatch_table[DETECT_CONTENT].Match = DetectContentMatch; sigmatch_table[DETECT_CONTENT].Setup = DetectContentSetup; - sigmatch_table[DETECT_CONTENT].Free = NULL; + sigmatch_table[DETECT_CONTENT].Free = DetectContentFree; sigmatch_table[DETECT_CONTENT].RegisterTests = DetectContentRegisterTests; /* create table for O(1) case conversion lookup */ @@ -440,7 +440,15 @@ error: * * \param cd pointer to DetectCotentData */ -void DetectContentFree(DetectContentData *cd) { +void DetectContentFree(void *ptr) { + DetectContentData *cd = (DetectContentData *)ptr; + + if (cd == NULL) + return; + + if (cd->content != NULL) + free(cd->content); + free(cd); } diff --git a/src/detect-flow.c b/src/detect-flow.c index e2da10eb00..f482d3036e 100644 --- a/src/detect-flow.c +++ b/src/detect-flow.c @@ -30,7 +30,7 @@ static pcre_extra *parse_regex_study; int DetectFlowMatch (ThreadVars *, PatternMatcherThread *, Packet *, Signature *, SigMatch *); int DetectFlowSetup (DetectEngineCtx *, Signature *, SigMatch *, char *); void DetectFlowRegisterTests(void); -void DetectFlowFree(DetectFlowData *); +void DetectFlowFree(void *); /** * \brief Registration function for flow: keyword @@ -40,7 +40,7 @@ void DetectFlowRegister (void) { sigmatch_table[DETECT_FLOW].name = "flow"; sigmatch_table[DETECT_FLOW].Match = DetectFlowMatch; sigmatch_table[DETECT_FLOW].Setup = DetectFlowSetup; - sigmatch_table[DETECT_FLOW].Free = NULL; + sigmatch_table[DETECT_FLOW].Free = DetectFlowFree; sigmatch_table[DETECT_FLOW].RegisterTests = DetectFlowRegisterTests; const char *eb; @@ -291,7 +291,8 @@ error: * * \param fd pointer to DetectFlowData */ -void DetectFlowFree(DetectFlowData *fd) { +void DetectFlowFree(void *ptr) { + DetectFlowData *fd = (DetectFlowData *)ptr; free(fd); } diff --git a/src/detect-flowbits.c b/src/detect-flowbits.c index 0127eec8d9..105936b4c7 100644 --- a/src/detect-flowbits.c +++ b/src/detect-flowbits.c @@ -38,12 +38,13 @@ static pcre_extra *parse_regex_study; int DetectFlowbitMatch (ThreadVars *, PatternMatcherThread *, Packet *, Signature *, SigMatch *); int DetectFlowbitSetup (DetectEngineCtx *, Signature *, SigMatch *, char *); +void DetectFlowbitFree (void *); void DetectFlowbitsRegister (void) { sigmatch_table[DETECT_FLOWBITS].name = "flowbits"; sigmatch_table[DETECT_FLOWBITS].Match = DetectFlowbitMatch; sigmatch_table[DETECT_FLOWBITS].Setup = DetectFlowbitSetup; - sigmatch_table[DETECT_FLOWBITS].Free = NULL; + sigmatch_table[DETECT_FLOWBITS].Free = DetectFlowbitFree; sigmatch_table[DETECT_FLOWBITS].RegisterTests = NULL; const char *eb; @@ -209,4 +210,12 @@ error: return -1; } +void DetectFlowbitFree (void *ptr) { + DetectFlowbitsData *fd = (DetectFlowbitsData *)ptr; + + if (fd == NULL) + return; + + free(fd); +} diff --git a/src/detect-pcre.c b/src/detect-pcre.c index de13782c9c..f8410b495e 100644 --- a/src/detect-pcre.c +++ b/src/detect-pcre.c @@ -25,7 +25,7 @@ static pcre_extra *parse_capture_regex_study; int DetectPcreMatch (ThreadVars *, PatternMatcherThread *, Packet *, Signature *, SigMatch *); int DetectPcreSetup (DetectEngineCtx *, Signature *, SigMatch *, char *); -int DetectPcreFree(SigMatch *); +void DetectPcreFree(void *); void DetectPcreRegister (void) { sigmatch_table[DETECT_PCRE].name = "pcre"; @@ -351,14 +351,14 @@ error: return -1; } -int DetectPcreFree(SigMatch *sm) { - DetectPcreData *pd = (DetectPcreData *)sm->ctx; +void DetectPcreFree(void *ptr) { + DetectPcreData *pd = (DetectPcreData *)ptr; if (pd->capname != NULL) free(pd->capname); if (pd->re != NULL) pcre_free(pd->re); if (pd->sd != NULL) pcre_free(pd->sd); - free(sm->ctx); - return 0; + free(pd); + return; } diff --git a/src/detect.h b/src/detect.h index 00deb0c93f..1fe853f817 100644 --- a/src/detect.h +++ b/src/detect.h @@ -301,7 +301,7 @@ typedef struct SigMatch_ { typedef struct SigTableElmt_ { int (*Match)(ThreadVars *, PatternMatcherThread *, Packet *, Signature *, SigMatch *); int (*Setup)(DetectEngineCtx *, Signature *, SigMatch *, char *); - int (*Free)(SigMatch *); + void (*Free)(void *); void (*RegisterTests)(void); uint8_t flags;