changeset 31014:490e8a6107d0 stable

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.
author John W. Eaton <jwe@octave.org>
date Tue, 24 May 2022 11:37:03 -0700
parents a1476e3ea73d
children a4a010d40459 8475b51b990c
files libinterp/octave-value/ov-fcn-handle.cc
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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_frame>& 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_frame>& 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
   {