Bug 1227642: Make data a ScopedJSFreePtr in js::detail::CopyScript to ensure it doesn't leak; r=jonco
authorBenjamin Bouvier <benj@benj.me>
Tue, 24 Nov 2015 19:35:19 +0100
changeset 274244 7d2d6e90fc1244a333ae8f1bc5d02353b901a4a2
parent 274243 31e6b15c28e416c7e55e527db79b4d10ab4ea978
child 274245 b8533b00af0a45fbc1e4f14ab3c52c92ee3e4a2f
push id29727
push usercbook@mozilla.com
push dateThu, 26 Nov 2015 15:54:54 +0000
treeherdermozilla-central@74c7941a9e22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjonco
bugs1227642
milestone45.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 1227642: Make data a ScopedJSFreePtr in js::detail::CopyScript to ensure it doesn't leak; r=jonco
js/src/jsscript.cpp
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -2815,19 +2815,19 @@ JSScript::partiallyInit(ExclusiveContext
         size_t vectorSize = nyieldoffsets * sizeof(script->yieldOffsets()[0]);
 #ifdef DEBUG
         memset(cursor, 0, vectorSize);
 #endif
         cursor += vectorSize;
     }
 
     if (script->bindings.count() != 0) {
-	// Make sure bindings are sufficiently aligned.
-	cursor = reinterpret_cast<uint8_t*>
-	    (JS_ROUNDUP(reinterpret_cast<uintptr_t>(cursor), JS_ALIGNMENT_OF(Binding)));
+        // Make sure bindings are sufficiently aligned.
+        cursor = reinterpret_cast<uint8_t*>
+            (JS_ROUNDUP(reinterpret_cast<uintptr_t>(cursor), JS_ALIGNMENT_OF(Binding)));
     }
     cursor = script->bindings.switchToScriptStorage(reinterpret_cast<Binding*>(cursor));
 
     MOZ_ASSERT(cursor == script->data + size);
     return true;
 }
 
 /* static */ bool
@@ -3395,17 +3395,17 @@ js::detail::CopyScript(JSContext* cx, Ha
     uint32_t nregexps  = src->hasRegexps()  ? src->regexps()->length  : 0;
     uint32_t ntrynotes = src->hasTrynotes() ? src->trynotes()->length : 0;
     uint32_t nblockscopes = src->hasBlockScopes() ? src->blockScopes()->length : 0;
     uint32_t nyieldoffsets = src->hasYieldOffsets() ? src->yieldOffsets().length() : 0;
 
     /* Script data */
 
     size_t size = src->dataSize();
-    uint8_t* data = AllocScriptData(cx->zone(), size);
+    ScopedJSFreePtr<uint8_t> data(AllocScriptData(cx->zone(), size));
     if (size && !data) {
         ReportOutOfMemory(cx);
         return false;
     }
 
     /* Bindings */
 
     Rooted<Bindings> bindings(cx);
@@ -3494,19 +3494,19 @@ js::detail::CopyScript(JSContext* cx, Ha
         }
     }
 
     /* Now that all fallible allocation is complete, do the copying. */
 
     dst->bindings = bindings;
 
     /* This assignment must occur before all the Rebase calls. */
-    dst->data = data;
+    dst->data = data.forget();
     dst->dataSize_ = size;
-    memcpy(data, src->data, size);
+    memcpy(dst->data, src->data, size);
 
     /* Script filenames, bytecodes and atoms are runtime-wide. */
     dst->setCode(src->code());
     dst->atoms = src->atoms;
 
     dst->setLength(src->length());
     dst->lineno_ = src->lineno();
     dst->mainOffset_ = src->mainOffset();