You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[[ Bug 16947 ]] Fix memory leak when making recursive calls with refs
This patch fixes a memory leak which can occur when a handler calls itself
and it uses reference parameters.
In order to fix the issue, calling of handlers has been refactored in
two ways.
First of all the MCComref and MCFuncref syntax node classes have been
moved to keywords.h and are now unified by both being implemented via
aggregating an MCHandref class (this means that they can share almost
all their implementation, and still retain distinct MCStatement and
MCExpression syntax node base classes).
Secondly, the calling of handlers has now been split into three parts:
setup, teardown and exec. The setup phase evaluates parameters, using
a pre-allocated vector of containers provided by the caller; the teardown
phase frees any resources allocated by setup. Critically this has
reduced the remit of the main handler exec function which means that
MCComref, MCFuncref *and* MCDispatchCmd can now share most of their
code.
The actual memory leak is fixed by moving ownership of any containers
required to invoke a handler to the caller of setup and teardown
phases. The number of containers required is precalculated after
parsing the expression list (as it is just the number of expressions
which have a root variable ref), and space for those that are required
when the call is invoked is allocated before setup is called.
The only difference between MCComref/MCFuncref and MCDispatchCmd is
now that the former use MCKeywordsExecCommandOrFunction to execute
the call whereas MCDispatchCmd uses MCEngineExecDispatch, directly
reflecting their key difference.
Additionally, MCParameter::eval or MCParameter::eval_ctxt have been
changed to only ever evaluate the expression bound to the parameter
rather than evaluating any set argument if present. Places where these
methods were being used to evaluate the set argument value have been updated
to use eval_argument and eval_argument_ctxt respectively.
0 commit comments