Bug 777083 - Don't leak when ownSource is true. r=luke
authorBenjamin Peterson <benjamin@python.org>
Tue, 24 Jul 2012 19:01:38 -0700
changeset 100350 a338900cf0af15b784a415dcceb4709f5ea355b6
parent 100349 ef6fac0c8330d947a37c281643326d336335945a
child 100356 2875cd2e7e621ecbfc6474e6c3ecded428ca5ea8
push id12456
push userbpeterson@mozilla.com
push dateWed, 25 Jul 2012 02:02:43 +0000
treeherdermozilla-inbound@a338900cf0af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs777083
milestone17.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 777083 - Don't leak when ownSource is true. r=luke
js/src/jsscript.cpp
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -1178,21 +1178,23 @@ ScriptSource::substring(JSContext *cx, u
 ScriptSource *
 ScriptSource::createFromSource(JSContext *cx, const jschar *src, uint32_t length,
                                bool argumentsNotIncluded, SourceCompressionToken *tok,
                                bool ownSource)
 {
     ScriptSource *ss = static_cast<ScriptSource *>(cx->malloc_(sizeof(*ss)));
     if (!ss)
         return NULL;
-    const size_t memlen = length * sizeof(jschar);
-    ss->data.compressed = static_cast<unsigned char *>(cx->malloc_(memlen));
-    if (!ss->data.compressed) {
-        cx->free_(ss);
-        return NULL;
+    if (!ownSource) {
+        const size_t memlen = length * sizeof(jschar);
+        ss->data.compressed = static_cast<unsigned char *>(cx->malloc_(memlen));
+        if (!ss->data.compressed) {
+            cx->free_(ss);
+            return NULL;
+        }
     }
     ss->next = NULL;
     ss->length_ = length;
     ss->compressedLength = 0;
     ss->marked = ss->onRuntime_ = false;
     ss->argumentsNotIncluded_ = argumentsNotIncluded;
 #ifdef DEBUG
     ss->ready_ = false;