changeset 24572:4711e4b649d5

fix memory leak with subfunctions and nested functions * ov-user-fcn.h, ov-user-fcn.cc (octave_user_function::parent_scope): Delete data member. (octave_user_function::parent_fcn_scope): Delete function. (octave_user_function::dump): Don't display parent scope name. (octave_user_function::stash_parent_fcn_scope): Avoid circular reference and memory leak by calling m_scope.set_parent instead of keeping a copy of the parent scope.
author John W. Eaton <jwe@octave.org>
date Tue, 09 Jan 2018 15:32:09 -0500
parents 7b6a5336ddb3
children 28a4037d10ab
files libinterp/octave-value/ov-usr-fcn.cc libinterp/octave-value/ov-usr-fcn.h
diffstat 2 files changed, 2 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-usr-fcn.cc	Tue Jan 09 08:56:31 2018 -0500
+++ b/libinterp/octave-value/ov-usr-fcn.cc	Tue Jan 09 15:32:09 2018 -0500
@@ -252,8 +252,7 @@
     num_named_args (param_list ? param_list->length () : 0),
     subfunction (false), inline_function (false),
     anonymous_function (false), nested_function (false),
-    class_constructor (none), class_method (false),
-    parent_scope ()
+    class_constructor (none), class_method (false)
 #if defined (HAVE_LLVM)
     , jit_info (0)
 #endif
@@ -362,7 +361,7 @@
 void
 octave_user_function::stash_parent_fcn_scope (const octave::symbol_scope& ps)
 {
-  parent_scope = ps;
+  m_scope.set_parent (ps);
 }
 
 std::string
@@ -760,7 +759,6 @@
        { "nested_function", nested_function },
        { "ctor_type", ctor_type_str () },
        { "class_method", class_method },
-       { "parent_scope", parent_scope ? parent_scope.name () : "0x0" },
        { "scope_info", m_scope ? m_scope.dump () : "0x0" }};
 
   return octave_value (m);
--- a/libinterp/octave-value/ov-usr-fcn.h	Tue Jan 09 08:56:31 2018 -0500
+++ b/libinterp/octave-value/ov-usr-fcn.h	Tue Jan 09 15:32:09 2018 -0500
@@ -280,9 +280,6 @@
 
   std::string parent_fcn_name (void) const { return parent_name; }
 
-  octave::symbol_scope
-  parent_fcn_scope (void) const { return parent_scope; }
-
   octave::sys::time time_parsed (void) const { return t_parsed; }
 
   octave::sys::time time_checked (void) const { return t_checked; }
@@ -480,9 +477,6 @@
   // TRUE means this function is a method for a class.
   bool class_method;
 
-  // The scope of the parent function, if any.
-  octave::symbol_scope parent_scope;
-
 #if defined (HAVE_LLVM)
   octave::jit_function_info *jit_info;
 #endif