]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rule-reload: Release excess memory freed during engine reload
authorThomas Winter <Thomas.Winter@alliedtelesis.co.nz>
Thu, 27 Apr 2023 04:08:46 +0000 (16:08 +1200)
committerVictor Julien <victor@inliniac.net>
Sun, 19 Nov 2023 06:25:11 +0000 (07:25 +0100)
The hot reload results in large chunks of memory being freed as the
as the old signature tables are discarded. Help the memory management
system along by telling to release as much memory as it can at this
point.

Bug: #6454.

configure.ac
src/detect-engine.c
src/suricata-common.h

index 1eb054d98c1e283c6f5429ec03ecc028e5a54f83..c2bed717616ca201f73fb6e17bf08fee770a6b07 100644 (file)
             #include <sys/random.h> 
             ])
 
+    AC_CHECK_HEADERS([malloc.h])
+    AC_CHECK_DECL([malloc_trim],
+        AC_DEFINE([HAVE_MALLOC_TRIM], [1], [Use malloc_trim]),
+        [], [
+            #include <malloc.h> 
+            ])
+
     OCFLAGS=$CFLAGS
     CFLAGS=""
     AC_CHECK_FUNCS([strlcpy strlcat])
index 0fc2df6869b0b8e19c31784b59ef15b9e2ae0558..25e76445edd99e9a3e2e1a482b04fdef06830431 100644 (file)
@@ -4797,6 +4797,15 @@ int DetectEngineReload(const SCInstance *suri)
     SCLogDebug("old_de_ctx should have been freed");
 
     SCLogNotice("rule reload complete");
+
+#ifdef HAVE_MALLOC_TRIM
+    /* The reload process potentially frees up large amounts of memory.
+     * Encourage the memory management system to reclaim as much as it
+     * can.
+     */
+    malloc_trim(0);
+#endif
+
     return 0;
 }
 
index 4aad25a252f45fb2e6c08940cdb0b380bcd0cefd..297a6fc4521e6339149a932ee07d95e3b7f21aec 100644 (file)
@@ -212,6 +212,10 @@ typedef unsigned char u_char;
 #include <netdb.h>
 #endif
 
+#if HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
 #if __CYGWIN__
 #if !defined _X86_ && !defined __x86_64
 #define _X86_