Bug 1022954 - ScriptSource leaks sourceMapURL_ sometimes. r=jimb
authorAndrew McCreight <continuation@gmail.com>
Thu, 10 Jul 2014 15:46:00 +0200
changeset 193556 5e318db257e74d3188e9304c2e0048d6bfa443b2
parent 193555 8acd862a180fd9926cddddd34bbd3a6038d2fa8f
child 193557 99bd46e9351759e6a4119c748a3182342eae4ee8
push id27123
push userryanvm@gmail.com
push dateFri, 11 Jul 2014 20:35:05 +0000
treeherdermozilla-central@84bd8d9f4256 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimb
bugs1022954
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1022954 - ScriptSource leaks sourceMapURL_ sometimes. r=jimb
build/sanitizers/lsan_suppressions.txt
content/base/test/chrome/nochrome_bug765993.js
js/src/jsscript.cpp
--- a/build/sanitizers/lsan_suppressions.txt
+++ b/build/sanitizers/lsan_suppressions.txt
@@ -60,19 +60,16 @@ leak:event_base_once
 leak:nsLocalFile::OpenNSPRFileDesc
 
 # Bug 1023585 - Leak of array buffer in JSStructuredCloneWriter::transferOwnership(). m1
 leak:AllocateArrayBufferContents
 
 # Bug 1022010 - Small leak under _render_glyph_outline. bc1
 leak:_render_glyph_outline
 
-# Bug 1022954 - ScriptSource leaks sourceMapURL_ sometimes. dt
-leak:ScriptSource::setSourceMapURL
-
 # Bug 1023548 - Small leak under SECITEM_AllocItem_Util. bc1, bc3
 leak:SECITEM_AllocItem_Util
 
 # This is a one-time leak, so it is probably okay to ignore. bc1, oth
 leak:GlobalPrinters::InitializeGlobalPrinters
 leak:nsPSPrinterList::GetPrinterList
 
 # Bug 1028456 - More leaks with _PR_Getfd, in nsLocalFile::CopyToNative and do_create. bc1, bc3
--- a/content/base/test/chrome/nochrome_bug765993.js
+++ b/content/base/test/chrome/nochrome_bug765993.js
@@ -1,4 +1,4 @@
-//@ sourceMappingURL=bar.js.map
+//# sourceMappingURL=bar.js.map
 
 // Define a single function to prevent script source from being gc'd
 function foo() {}
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -1859,16 +1859,17 @@ ScriptSource::performXDR(XDRState<mode> 
 
     if (haveSourceMap) {
         uint32_t sourceMapURLLen = (mode == XDR_DECODE) ? 0 : js_strlen(sourceMapURL_);
         if (!xdr->codeUint32(&sourceMapURLLen))
             return false;
 
         if (mode == XDR_DECODE) {
             size_t byteLen = (sourceMapURLLen + 1) * sizeof(jschar);
+            MOZ_ASSERT(!sourceMapURL_, "Don't leak sourceMapURL_");
             sourceMapURL_ = static_cast<jschar *>(xdr->cx()->malloc_(byteLen));
             if (!sourceMapURL_)
                 return false;
         }
         if (!xdr->codeChars(sourceMapURL_, sourceMapURLLen)) {
             if (mode == XDR_DECODE) {
                 js_free(sourceMapURL_);
                 sourceMapURL_ = nullptr;
@@ -2030,24 +2031,26 @@ ScriptSource::displayURL()
     return displayURL_;
 }
 
 bool
 ScriptSource::setSourceMapURL(ExclusiveContext *cx, const jschar *sourceMapURL)
 {
     JS_ASSERT(sourceMapURL);
     if (hasSourceMapURL()) {
-        if (cx->isJSContext() &&
-            !JS_ReportErrorFlagsAndNumber(cx->asJSContext(), JSREPORT_WARNING,
-                                          js_GetErrorMessage, nullptr,
-                                          JSMSG_ALREADY_HAS_PRAGMA, filename_,
-                                          "//# sourceMappingURL"))
-        {
-            return false;
+        // Warn about the replacement, but use the new one.
+        if (cx->isJSContext()) {
+            JS_ReportErrorFlagsAndNumber(cx->asJSContext(), JSREPORT_WARNING,
+                                         js_GetErrorMessage, nullptr,
+                                         JSMSG_ALREADY_HAS_PRAGMA, filename_,
+                                         "//# sourceMappingURL");
         }
+
+        js_free(sourceMapURL_);
+        sourceMapURL_ = nullptr;
     }
 
     size_t len = js_strlen(sourceMapURL) + 1;
     if (len == 1)
         return true;
     sourceMapURL_ = js_strdup(cx, sourceMapURL);
     if (!sourceMapURL_)
         return false;