Bug 676934 - Limit number of stack frame objects created by XPCJSStackFrame::CreateStack (r=mrbkap)
authorLuke Wagner <luke@mozilla.com>
Mon, 22 Aug 2011 16:35:17 -0700
changeset 77494 363c40e0666704df081098a50d2c1c01feff7e98
parent 77493 dbc9ed28ba955eec60494297f3cad9c3114a06d1
child 77495 9c15d0fb3e255648d8050634a073033732ca705e
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs676934
milestone9.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 676934 - Limit number of stack frame objects created by XPCJSStackFrame::CreateStack (r=mrbkap)
js/src/xpconnect/src/xpcstack.cpp
--- a/js/src/xpconnect/src/xpcstack.cpp
+++ b/js/src/xpconnect/src/xpcstack.cpp
@@ -128,16 +128,19 @@ XPCJSStackFrame::~XPCJSStackFrame()
 }
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(XPCJSStackFrame, nsIStackFrame)
 
 nsresult
 XPCJSStackFrame::CreateStack(JSContext* cx, JSStackFrame* fp,
                              XPCJSStackFrame** stack)
 {
+    static const unsigned MAX_FRAMES = 3000;
+    unsigned numFrames = 0;
+
     nsRefPtr<XPCJSStackFrame> first = new XPCJSStackFrame();
     nsRefPtr<XPCJSStackFrame> self = first;
     while(fp && self)
     {
         if(!JS_IsScriptFrame(cx, fp))
         {
             self->mLanguage = nsIProgrammingLanguage::CPLUSPLUS;
         }
@@ -182,17 +185,21 @@ XPCJSStackFrame::CreateStack(JSContext* 
                 }
             }
             else
             {
                 self->mLanguage = nsIProgrammingLanguage::CPLUSPLUS;
             }
         }
 
-        if(JS_FrameIterator(cx, &fp))
+        if (++numFrames > MAX_FRAMES)
+        {
+            fp = NULL;
+        }
+        else if(JS_FrameIterator(cx, &fp))
         {
             XPCJSStackFrame* frame = new XPCJSStackFrame();
             self->mCaller = frame;
             self = frame;
         }
     }
 
     *stack = first.forget().get();