Skip to content

Commit 36659e8

Browse files
author
Jianchun Xu
committed
pin Debugger::m_context
Found under stress unit testing. Debugger::m_context was not pinned and could be GC collected when not in use.
1 parent 6552a52 commit 36659e8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

bin/ch/Debugger.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ Debugger::Debugger(JsRuntimeHandle runtime)
192192

193193
Debugger::~Debugger()
194194
{
195+
if (this->m_context != JS_INVALID_REFERENCE)
196+
{
197+
ChakraRTInterface::JsRelease(this->m_context, nullptr);
198+
this->m_context = JS_INVALID_REFERENCE;
199+
}
195200
this->m_runtime = JS_INVALID_RUNTIME_HANDLE;
196201
}
197202

@@ -225,7 +230,9 @@ bool Debugger::Initialize()
225230
// Create a new context and run dbgcontroller.js in that context
226231
// setup dbgcontroller.js callbacks
227232

233+
Assert(this->m_context == JS_INVALID_REFERENCE);
228234
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateContext(this->m_runtime, &this->m_context));
235+
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsAddRef(this->m_context, nullptr)); // Pin context
229236

230237
AutoRestoreContext autoRestoreContext(this->m_context);
231238

0 commit comments

Comments
 (0)