Skip to content

Commit 9cb45a9

Browse files
committed
[MERGE chakra-core#728] Fixing a potential OOM point
Merge pull request chakra-core#728 from rajatd:OOM I stumbled across this piece of code while inestigating another issue. We are calling CloneIfStaticExceptionObject inside a catch. This could potentially throw OOM if the caught exception was an out of memory exception. Changing the code here to conform to the pattern used at other places - save the exception object in a local and take action on that local outside the catch. This reduces the chances of an OOM being thrown as the stack would have been unwound when we get outside the catch block.
2 parents 8dd3b90 + 295a388 commit 9cb45a9

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4810,18 +4810,23 @@ namespace Js
48104810
// For Intl builtins, we need to make sure the Intl object has been initialized before fetching the
48114811
// builtins from the EngineInterfaceObject. This is because the builtins are actually created via
48124812
// Intl.js and are registered into the EngineInterfaceObject as part of Intl object initialization.
4813+
JavascriptExceptionObject * caughtExceptionObject = nullptr;
48134814
try
48144815
{
48154816
this->IntlObject->GetTypeHandler()->EnsureObjectReady(this->IntlObject);
4816-
} catch (JavascriptExceptionObject *e)
4817+
}
4818+
catch (JavascriptExceptionObject *e)
48174819
{
4818-
// Propagate the OOM and SOE exceptions only
4819-
if (e == ThreadContext::GetContextForCurrentThread()->GetPendingOOMErrorObject() ||
4820-
e == ThreadContext::GetContextForCurrentThread()->GetPendingSOErrorObject())
4821-
{
4822-
e = e->CloneIfStaticExceptionObject(scriptContext);
4823-
throw e;
4824-
}
4820+
caughtExceptionObject = e;
4821+
}
4822+
4823+
// Propagate the OOM and SOE exceptions only
4824+
if (caughtExceptionObject != nullptr &&
4825+
(caughtExceptionObject == ThreadContext::GetContextForCurrentThread()->GetPendingOOMErrorObject() ||
4826+
caughtExceptionObject == ThreadContext::GetContextForCurrentThread()->GetPendingSOErrorObject()))
4827+
{
4828+
caughtExceptionObject = caughtExceptionObject->CloneIfStaticExceptionObject(scriptContext);
4829+
throw caughtExceptionObject;
48254830
}
48264831
}
48274832

0 commit comments

Comments
 (0)