# HG changeset patch # User John W. Eaton # Date 1653417423 25200 # Node ID 490e8a6107d05af8085e4b87832dce709307fe22 # Parent a1476e3ea73d81577fb19c9c3b23e1d6ad20b821 Fix memory leak with nested functions and anonymous functions (bug #62459) * ov-fcn-handle.cc (nested_fcn_handle::nested_fcn_handle, anonymous_fcn_handle::anonymous_fcn_handle): Call mark_closure_context() in constructor. diff -r a1476e3ea73d -r 490e8a6107d0 libinterp/octave-value/ov-fcn-handle.cc --- a/libinterp/octave-value/ov-fcn-handle.cc Mon May 23 21:02:12 2022 -0700 +++ b/libinterp/octave-value/ov-fcn-handle.cc Tue May 24 11:37:03 2022 -0700 @@ -393,7 +393,8 @@ const std::shared_ptr& stack_context) : base_nested_fcn_handle (fcn, name), m_stack_context (stack_context) { - m_stack_context->mark_closure_context (); + if (m_stack_context) + m_stack_context->mark_closure_context (); } nested_fcn_handle (const nested_fcn_handle&) = default; @@ -2690,7 +2691,10 @@ const std::shared_ptr& stack_context) : base_anonymous_fcn_handle (fcn, local_vars), m_stack_context (stack_context) - { } + { + if (m_stack_context) + m_stack_context->mark_closure_context (); + } octave_value anonymous_fcn_handle::make_weak_anonymous_handle (void) const {