Skip to content

Commit

Permalink
Address CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeHolman committed Dec 14, 2017
1 parent 8436868 commit a0fd3cd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/JITServer/JITServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,15 @@ ServerInitializeThreadContext(
}
catch (Js::OutOfMemoryException)
{
if (!contextInfo)
if (contextInfo)
{
// If we OOM while registering the ThreadContext, we need to free it
HeapDelete(contextInfo);
}
else
{
// If we OOM while creating the ThreadContext, then we haven't transfered ownership
// of the ProcessContext reference, so we must release it here
processContext->Release();
}
return E_OUTOFMEMORY;
Expand Down Expand Up @@ -870,7 +877,7 @@ ProcessContextManager::RegisterNewProcess(DWORD pid, HANDLE processHandle, intpt
{
ProcessContext* context = iter.CurrentValue();
// We can delete a ProcessContext if no ThreadContexts refer to it and the process is terminated
if (!context->HasRef() && WaitForSingleObject(context->processHandle, 0) != WAIT_TIMEOUT)
if (!context->HasRef() && WaitForSingleObject(context->processHandle, 0) == WAIT_OBJECT_0)
{
iter.RemoveCurrent();
HeapDelete(context);
Expand All @@ -882,15 +889,21 @@ ProcessContextManager::RegisterNewProcess(DWORD pid, HANDLE processHandle, intpt
return E_ACCESSDENIED;
}

ProcessContext* context = nullptr;
try
{
AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory));

ProcessContext* context = HeapNew(ProcessContext, processHandle, chakraBaseAddress, crtBaseAddress);
context = HeapNew(ProcessContext, processHandle, chakraBaseAddress, crtBaseAddress);
ProcessContexts.Add(pid, context);
}
catch (Js::OutOfMemoryException)
{
if (context != nullptr)
{
// If we OOM while registering the ProcessContext, we should free it
HeapDelete(context);
}
return E_OUTOFMEMORY;
}

Expand Down

0 comments on commit a0fd3cd

Please sign in to comment.