From bc09ce4e25ff2c361d19ace35e556b738651c0a2 Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Sun, 24 Jan 2021 17:55:23 +0300 Subject: [PATCH] Force Glibc to free the memory freed configure.ac: check whether malloc_trim is suported src/alloc.c (garbage_collect): call malloc_trim() if possible (bug#45200) --- configure.ac | 3 +++ src/alloc.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 08f3c0cd85..416cfbe389 100644 --- a/configure.ac +++ b/configure.ac @@ -4556,6 +4556,9 @@ AC_DEFUN dnl the current CFLAGS etc. AC_CHECK_FUNCS(snprintf) + +AC_CHECK_FUNCS(malloc_trim) + dnl Check for glib. This differs from other library checks in that dnl Emacs need not link to glib unless some other library is already dnl linking to glib. Although glib provides no facilities that Emacs diff --git a/src/alloc.c b/src/alloc.c index b86ed4ed26..3124378fb8 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -6146,6 +6146,9 @@ garbage_collect (void) if (tot_after < tot_before) malloc_probe (min (tot_before - tot_after, SIZE_MAX)); } +#ifdef HAVE_MALLOC_TRIM + malloc_trim(0); /* work around for high memory consumption, see bug 45200 */ +#endif /* HAVE_MALLOC_TRIM */ } DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", -- 2.30.0