diff --git a/configure.ac b/configure.ac index 1eb054d98c..c2bed71761 100644 --- a/configure.ac +++ b/configure.ac @@ -220,6 +220,13 @@ #include ]) + AC_CHECK_HEADERS([malloc.h]) + AC_CHECK_DECL([malloc_trim], + AC_DEFINE([HAVE_MALLOC_TRIM], [1], [Use malloc_trim]), + [], [ + #include + ]) + OCFLAGS=$CFLAGS CFLAGS="" AC_CHECK_FUNCS([strlcpy strlcat]) diff --git a/src/detect-engine.c b/src/detect-engine.c index 0fc2df6869..25e76445ed 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -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; } diff --git a/src/suricata-common.h b/src/suricata-common.h index 4aad25a252..297a6fc452 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -212,6 +212,10 @@ typedef unsigned char u_char; #include #endif +#if HAVE_MALLOC_H +#include +#endif + #if __CYGWIN__ #if !defined _X86_ && !defined __x86_64 #define _X86_