Bug 976777: Truncate long source lines in script errors before sending them to the parent process. r=bent

This fixes an out-of-memory foreground-tab crash that I could reliably
reproduce on a 256MB Firefox OS phone, and I think also significantly
reduces the number of background tabs I'm seeing killed due to low
memory.
This commit is contained in:
L. David Baron 2014-03-04 20:13:19 -08:00
parent f5edb56a68
commit 449dc2dfe0

View File

@ -268,6 +268,16 @@ ConsoleListener::Observe(nsIConsoleMessage* aMessage)
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetSourceLine(sourceLine);
NS_ENSURE_SUCCESS(rv, rv);
// Before we send the error to the parent process (which
// involves copying the memory), truncate any long lines. CSS
// errors in particular share the memory for long lines with
// repeated errors, but the IPC communication we're about to do
// will break that sharing, so we better truncate now.
if (sourceLine.Length() > 1000) {
sourceLine.Truncate(1000);
}
rv = scriptError->GetCategory(getter_Copies(category));
NS_ENSURE_SUCCESS(rv, rv);
rv = scriptError->GetLineNumber(&lineNum);