From 2195e2cf713f974c8774d23ae47e35ea7117e0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 3 Nov 2019 12:48:18 +0100 Subject: [PATCH] terminal: trim memory after free:ing a terminal A terminal with lots of scrollback history will have allocated a lot of memory. Normally, free() wont return this memory to the OS, and we don't seem to trigger the automatic trim calls. This means the server would accumulate quite a lot of memory over time, as terminals come and go. Now we explicitly trim the memory every time a terminal is destroyed. --- terminal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/terminal.c b/terminal.c index 8d5e195f..56cf8d69 100644 --- a/terminal.c +++ b/terminal.c @@ -1,5 +1,6 @@ #include "terminal.h" +#include #include #include #include @@ -796,6 +797,8 @@ term_destroy(struct terminal *term) } free(term); + if (!malloc_trim(0)) + LOG_WARN("failed to trim memory"); return ret; }