From 033409a042eccc1cba0d87b07fbd1c6ee7cb0cfe Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sun, 26 Oct 2014 09:02:08 +0100 Subject: [PATCH] iprep: cleanup ctx on shutdown ~~Dr.M~~ Error #1: LEAK 480 direct bytes 0x0aae7fc0-0x0aae81a0 + 0 indirect bytes ~~Dr.M~~ # 0 replace_malloc [/work/drmemory_package/common/alloc_replace.c:2373] ~~Dr.M~~ # 1 SRepInit [.../Suricata/src/reputation.c:594] ~~Dr.M~~ # 2 DetectEngineCtxInit [.../src/detect-engine.c:844] ~~Dr.M~~ # 3 main [.../Suricata/src/suricata.c:2230] --- src/detect-engine.c | 1 + src/reputation.c | 20 ++++++++++++++++++++ src/reputation.h | 1 + 3 files changed, 22 insertions(+) diff --git a/src/detect-engine.c b/src/detect-engine.c index 6c60a8540f..6b80748fbe 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -916,6 +916,7 @@ void DetectEngineCtxFree(DetectEngineCtx *de_ctx) } DetectEngineCtxFreeThreadKeywordData(de_ctx); + SRepDestroy(de_ctx); SCFree(de_ctx); //DetectAddressGroupPrintMemory(); //DetectSigGroupPrintMemory(); diff --git a/src/reputation.c b/src/reputation.c index bce8946ad7..23484f08b0 100644 --- a/src/reputation.c +++ b/src/reputation.c @@ -664,6 +664,26 @@ int SRepInit(DetectEngineCtx *de_ctx) return 0; } +void SRepDestroy(DetectEngineCtx *de_ctx) { + if (de_ctx->srepCIDR_ctx != NULL) { + int i; + for (i = 0; i < SREP_MAX_CATS; i++) { + if (de_ctx->srepCIDR_ctx->srepIPV4_tree[i] != NULL) { + SCRadixReleaseRadixTree(de_ctx->srepCIDR_ctx->srepIPV4_tree[i]); + de_ctx->srepCIDR_ctx->srepIPV4_tree[i] = NULL; + } + + if (de_ctx->srepCIDR_ctx->srepIPV6_tree[i] != NULL) { + SCRadixReleaseRadixTree(de_ctx->srepCIDR_ctx->srepIPV6_tree[i]); + de_ctx->srepCIDR_ctx->srepIPV6_tree[i] = NULL; + } + } + + SCFree(de_ctx->srepCIDR_ctx); + de_ctx->srepCIDR_ctx = NULL; + } +} + #ifdef UNITTESTS #include "conf-yaml-loader.h" diff --git a/src/reputation.h b/src/reputation.h index d489b1ff80..347731fe7b 100644 --- a/src/reputation.h +++ b/src/reputation.h @@ -42,6 +42,7 @@ typedef struct SReputation_ { uint8_t SRepCatGetByShortname(char *shortname); int SRepInit(struct DetectEngineCtx_ *de_ctx); +void SRepDestroy(struct DetectEngineCtx_ *de_ctx); void SRepReloadComplete(void); int SRepHostTimedOut(Host *); -- 2.47.3