[INFER] Fix memory leaks.
authorBrian Hackett <bhackett1024@gmail.com>
Sun, 15 May 2011 23:32:21 -0700
changeset 75061 cd6b101733b3d5040e8600cd4fdf158b5950ffa6
parent 75060 88112acd30942e660cf4730f401624d451d54e22
child 75062 118fb707c569d6d60cdd0bf5bc66bd45f5c92f13
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
milestone6.0a1
[INFER] Fix memory leaks.
js/src/jsanalyze.cpp
js/src/methodjit/Compiler.cpp
--- a/js/src/jsanalyze.cpp
+++ b/js/src/jsanalyze.cpp
@@ -44,17 +44,17 @@
 
 #include "jsinferinlines.h"
 #include "jsobjinlines.h"
 
 void
 JSScript::makeAnalysis(JSContext *cx)
 {
     JS_ASSERT(!analysis_);
-    analysis_ = cx->new_<js::analyze::ScriptAnalysis>(this);
+    analysis_ = js::ArenaNew<js::analyze::ScriptAnalysis>(cx->compartment->pool, this);
 }
 
 namespace js {
 namespace analyze {
 
 /////////////////////////////////////////////////////////////////////
 // Bytecode
 /////////////////////////////////////////////////////////////////////
@@ -1185,16 +1185,22 @@ ScriptAnalysis::analyzeSSA(JSContext *cx
      * untracked entries, i.e. escaping locals and arguments.
      */
     SSAValue *values = (SSAValue *)
         cx->calloc_((numSlots + maxDepth) * sizeof(SSAValue));
     if (!values) {
         setOOM(cx);
         return;
     }
+    struct FreeSSAValues {
+        JSContext *cx;
+        SSAValue *values;
+        FreeSSAValues(JSContext *cx, SSAValue *values) : cx(cx), values(values) {}
+        ~FreeSSAValues() { cx->free_(values); }
+    } free(cx, values);
 
     SSAValue *stack = values + numSlots;
     uint32 stackDepth = 0;
 
     for (uint32 slot = ArgSlot(0); slot < numSlots; slot++) {
         if (trackSlot(slot))
             values[slot].initInitial(slot);
     }
--- a/js/src/methodjit/Compiler.cpp
+++ b/js/src/methodjit/Compiler.cpp
@@ -560,24 +560,32 @@ mjit::Compiler::ActiveFrame::ActiveFrame
       inlineIndex(uint32(-1)), needReturnValue(false), syncReturnValue(false),
       returnValueDouble(false), returnSet(false), returnEntry(NULL),
       returnJumps(NULL), exitState(NULL)
 {}
 
 mjit::Compiler::ActiveFrame::~ActiveFrame()
 {
     js::Foreground::free_(jumpMap);
+    if (varTypes)
+        js::Foreground::free_(varTypes);
 }
 
 mjit::Compiler::~Compiler()
 {
     if (outer)
         cx->delete_(outer);
     for (unsigned i = 0; i < inlineFrames.length(); i++)
         cx->delete_(inlineFrames[i]);
+    while (loop) {
+        LoopState *nloop = loop->outer;
+        cx->delete_(loop);
+        loop = nloop;
+    }
+
 #ifdef DEBUG
     if (pcProfile)
         cx->free_(pcProfile);
 #endif
 }
 
 CompileStatus
 mjit::Compiler::prepareInferenceTypes(JSScript *script, ActiveFrame *a)