desktop/source/lib/init.cxx |   12 ++++++++++++
 1 file changed, 12 insertions(+)

New commits:
commit 15f0fd06346618c772466993598df5fd25181202
Author:     Michael Meeks <[email protected]>
AuthorDate: Wed Apr 12 16:01:46 2023 +0100
Commit:     Michael Meeks <[email protected]>
CommitDate: Thu Apr 13 10:45:38 2023 +0200

    lok: trim glibc allocator's pending heap when called.
    
    Change-Id: I8d1bda01a0e6ccff0fa868013c67c0fbbf78a836
    Signed-off-by: Michael Meeks <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150299
    Tested-by: Jenkins

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 49d4298c7a66..a4f34cc349e8 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -26,8 +26,14 @@
 #include <postmac.h>
 #endif
 
+#undef HAVE_MALLOC_TRIM
+
 #ifdef LINUX
 #include <fcntl.h>
+#if defined __GLIBC__
+#  include <malloc.h>
+#  define HAVE_MALLOC_TRIM
+#endif
 #endif
 
 #ifdef ANDROID
@@ -3146,6 +3152,12 @@ static char* lo_extractRequest(LibreOfficeKit* 
/*pThis*/, const char* pFilePath)
 static void lo_trimMemory(LibreOfficeKit* /* pThis */, int nTarget)
 {
     vcl::lok::trimMemory(nTarget);
+    if (nTarget > 1000)
+    {
+#ifdef HAVE_MALLOC_TRIM
+        malloc_trim(0);
+#endif
+    }
 }
 
 static void lo_registerCallback (LibreOfficeKit* pThis,

Reply via email to