Skip to content

Commit feea030

Browse files
committed
[CID 16095] libscript: MCScriptCallHandlerOfInstanceInternal(): Resource leak
1 parent e94c098 commit feea030

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

libscript/src/script-instance.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,30 +2157,33 @@ bool MCScriptCallHandlerOfInstanceInternal(MCScriptInstanceRef self, MCScriptHan
21572157
if (t_handler_definition -> function == nil)
21582158
{
21592159
if (!MCScriptPrepareForeignFunction(t_frame, t_instance, t_handler_definition, false, t_bound))
2160-
return false;
2160+
t_success = false;
21612161
}
21622162
else
21632163
t_bound = true;
21642164

2165-
if (t_bound)
2165+
if (t_success)
21662166
{
2167-
// The context struct is 'moved' into the handlerref.
2168-
__MCScriptHandlerContext t_context;
2169-
t_context . instance = MCScriptRetainInstance(t_instance);
2170-
t_context . definition = t_handler_definition;
2167+
if (t_bound)
2168+
{
2169+
// The context struct is 'moved' into the handlerref.
2170+
__MCScriptHandlerContext t_context;
2171+
t_context . instance = MCScriptRetainInstance(t_instance);
2172+
t_context . definition = t_handler_definition;
21712173

2172-
MCHandlerRef t_value;
2173-
t_success = MCHandlerCreate(t_signature, &__kMCScriptHandlerCallbacks, &t_context, t_value);
2174+
MCHandlerRef t_value;
2175+
t_success = MCHandlerCreate(t_signature, &__kMCScriptHandlerCallbacks, &t_context, t_value);
21742176

2175-
if (t_success)
2176-
{
2177-
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, t_value);
2178-
MCValueRelease(t_value);
2179-
}
2180-
}
2181-
else
2182-
{
2183-
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, kMCNull);
2177+
if (t_success)
2178+
{
2179+
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, t_value);
2180+
MCValueRelease(t_value);
2181+
}
2182+
}
2183+
else
2184+
{
2185+
t_success = MCScriptCheckedStoreToRegisterInFrame(t_frame, t_dst, kMCNull);
2186+
}
21842187
}
21852188
}
21862189
}

0 commit comments

Comments
 (0)