From 832a1f65dc87dc2662966d53285aa597e68435a8 Mon Sep 17 00:00:00 2001 From: "erikkay@google.com" Date: Fri, 8 Aug 2008 21:49:40 +0000 Subject: Limit the number of console messages we keep in memory so a poorly behaving script does not cause unbounded memory growth. This should likely be fixed upstream as well, but I think we should do it locally for beta. BUG=1313462 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@595 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/port/page/inspector/InspectorController.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'webkit') diff --git a/webkit/port/page/inspector/InspectorController.cpp b/webkit/port/page/inspector/InspectorController.cpp index 3c1a551..3b90744 100644 --- a/webkit/port/page/inspector/InspectorController.cpp +++ b/webkit/port/page/inspector/InspectorController.cpp @@ -101,6 +101,9 @@ using namespace std; namespace WebCore { +// Maximum size of the console message cache. +static const int MAX_CONSOLE_MESSAGES = 250; + namespace bug1228513 { // TODO(ericroman): Temporary hacks to help diagnose http://b/1228513 @@ -1377,6 +1380,18 @@ void InspectorController::addConsoleMessage(ConsoleMessage* consoleMessage) ASSERT(enabled()); ASSERT_ARG(consoleMessage, consoleMessage); + // Limit the number of console messages we keep in memory so a poorly + // behaving script doesn't cause unbounded memory growth. We remove the + // oldest messages so that the most recent errors are preserved. + // TODO(erikkay): this is not very efficient since Vector has to do a copy + // when you remove from anywhere other than the end. Unfortunately, WTF + // doesn't appear to have a double-ended list we could use instead. The + // extra CPU cost is definitely better than the memory cost. + if (m_consoleMessages.size() >= MAX_CONSOLE_MESSAGES) { + ConsoleMessage* msg = m_consoleMessages[0]; + m_consoleMessages.remove(0); + delete msg; + } m_consoleMessages.append(consoleMessage); if (windowVisible()) -- cgit v1.1