From 0d1ffd2c163d6e8c15b66bcd4e80bba21b5994d6 Mon Sep 17 00:00:00 2001 From: Patrick Luby Date: Thu, 22 Jun 2023 08:13:42 +0100 Subject: Limit memory usage of internal log storage. Otherwise it could grow without bound; now limited to 100 entries, each of <128 characters. Change-Id: I6a1b96a8cb6a67f991c3870f5b724989f65e0e74 Signed-off-by: Michael Meeks --- browser/src/core/Log.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/browser/src/core/Log.js b/browser/src/core/Log.js index c2efd6b418..19651f0ec4 100644 --- a/browser/src/core/Log.js +++ b/browser/src/core/Log.js @@ -11,6 +11,14 @@ L.Log = { if (!this._logs) { this._logs = []; } + // Limit memory usage of log by only keeping the latest entries + var maxEntries = 100; + while (this._logs.length > maxEntries) + this._logs.shift(); + // Limit memory usage of log by limiting length of message + var maxMsgLen = 128; + if (msg.length > maxMsgLen) + msg = msg.substring(0, maxMsgLen); msg = msg.replace(/(\r\n|\n|\r)/gm, ' '); this._logs.push({msg : msg, direction : direction, coords : tileCoords, time : time}); -- cgit