changeset 29545:841ca9987302 stable

perform shutdown actions in interpreter destructor (bug #60334) * interpreter.cc (interpreter::~interpreter): Call shutdown. (interpreter::shutdown): Return immediately if m_initialized is false and set m_initialized to false to prevent shutdown from being executed recursively. * embedded.cc (main): Don't call shutdown for interpreter object. * octave.cc (cli_application::execute): Likewise.
author John W. Eaton <jwe@octave.org>
date Tue, 20 Apr 2021 16:20:10 -0400
parents 6dfc06f55cd2
children 58e1230b9503 99e3912441ec
files examples/code/embedded.cc libinterp/corefcn/interpreter.cc libinterp/octave.cc
diffstat 3 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/examples/code/embedded.cc	Wed Apr 14 15:03:09 2021 +0200
+++ b/examples/code/embedded.cc	Tue Apr 20 16:20:10 2021 -0400
@@ -76,8 +76,5 @@
       std::cerr << "error encountered in Octave evaluator!" << std::endl;
     }
 
-  // Shutdown the interpreter which cleanly releases all memory.
-  interpreter.shutdown ();
-
   return 0;
 }
--- a/libinterp/corefcn/interpreter.cc	Wed Apr 14 15:03:09 2021 +0200
+++ b/libinterp/corefcn/interpreter.cc	Tue Apr 20 16:20:10 2021 -0400
@@ -635,6 +635,8 @@
 
   interpreter::~interpreter (void)
   {
+    shutdown ();
+
     delete m_gh_manager;
   }
 
@@ -845,6 +847,13 @@
 
   void interpreter::shutdown (void)
   {
+    // Attempt to prevent more than one call to shutdown.
+
+    if (! m_initialized)
+      return;
+
+    m_initialized = false;
+
     OCTAVE_SAFE_CALL (feval, ("close", ovl ("all"), 0));
 
     // If we are attached to a GUI, process pending events and
--- a/libinterp/octave.cc	Wed Apr 14 15:03:09 2021 +0200
+++ b/libinterp/octave.cc	Tue Apr 20 16:20:10 2021 -0400
@@ -378,8 +378,6 @@
 
     int status = interp.execute ();
 
-    interp.shutdown ();
-
     return status;
   }
 }