octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: segfault and onCleanup()


From: John W. Eaton
Subject: Re: segfault and onCleanup()
Date: Thu, 8 Dec 2011 15:37:39 -0500

On  8-Dec-2011, Ben Abbott wrote:

| When the tests complete and I "quit" ...
| 
| Program received signal EXC_BAD_ACCESS, Could not access memory.
| Reason: KERN_INVALID_ADDRESS at address: 0x000000010cf9e118
| 0x00000001001ee9d7 in std::_Rb_tree<std::string, std::pair<std::string const, 
graphics_toolkit>, std::_Select1st<std::pair<std::string const, 
graphics_toolkit> >, std::less<std::string>, 
std::allocator<std::pair<std::string const, graphics_toolkit> > >::_M_erase 
(this=0x100c37720, __x=<value temporarily unavailable, due to optimizations>) 
at graphics.h:2177
| 2177          delete rep;
| (gdb) bt
| #0  0x00000001001ee9d7 in std::_Rb_tree<std::string, std::pair<std::string 
const, graphics_toolkit>, std::_Select1st<std::pair<std::string const, 
graphics_toolkit> >, std::less<std::string>, 
std::allocator<std::pair<std::string const, graphics_toolkit> > >::_M_erase 
(this=0x100c37720, __x=<value temporarily unavailable, due to optimizations>) 
at graphics.h:2177
| #1  0x00007fff8526c7c8 in __cxa_finalize ()
| #2  0x00007fff8526c652 in exit ()
| #3  0x00000001003918ff in clean_up_and_exit (retval=<value temporarily 
unavailable, due to optimizations>) at toplev.cc:685
| #4  0x0000000100392420 in main_loop () at toplev.cc:641
| #5  0x0000000100324fdf in octave_main (argc=<value temporarily unavailable, 
due to optimizations>, argv=<value temporarily unavailable, due to 
optimizations>, embedded=0) at octave.cc:938
| #6  0x0000000100000f44 in start ()
| Current language:  auto; currently c++

OK, line 2177 in graphics.h is inside the destructor for the
graphics_toolkit object, and that is being called by exit.  I
intended to explicitly close and delete toolkit objects before this
point.  Does the following patch work for you?  If so, I think I will
take some time to try to fix this bug report:

  https://savannah.gnu.org/bugs/?31583

by making it possible for toolkits to be registered without being
loaded.

jwe

diff --git a/src/graphics.cc b/src/graphics.cc
--- a/src/graphics.cc
+++ b/src/graphics.cc
@@ -2890,19 +2890,6 @@
   return available_toolkits["gnuplot"];
 }
 
-void
-graphics_toolkit::close_all_toolkits (void)
-{
-  while (! available_toolkits.empty ())
-    {
-      available_toolkits_iterator p = available_toolkits.begin ();
-
-      p->second.close ();
-
-      available_toolkits.erase (p);
-    }
-}
-
 std::map<std::string, graphics_toolkit> graphics_toolkit::available_toolkits;
 
 // ---------------------------------------------------------------------
diff --git a/src/graphics.h.in b/src/graphics.h.in
--- a/src/graphics.h.in
+++ b/src/graphics.h.in
@@ -2236,8 +2236,6 @@
   // Close the graphics toolkit.
   void close (void) { rep->close (); }
 
-  void close_all_toolkits (void);
-
   OCTINTERP_API static graphics_toolkit default_toolkit (void);
 
   static void register_toolkit (const graphics_toolkit& b)
@@ -2269,6 +2267,23 @@
     return m;
   }
 
+  static void close_all_toolkits (void)
+  {
+    while (! available_toolkits.empty ())
+      {
+        available_toolkits_iterator p = available_toolkits.begin ();
+
+        std::string name = p->first;
+
+        p->second.close ();
+
+        // The toolkit may have unregistered itself.  If not, we'll do
+        // it here.
+        if (available_toolkits.find (name) != available_toolkits.end ())
+          unregister_toolkit (name);
+      }
+  }
+
 private:
   base_graphics_toolkit *rep;
 
diff --git a/src/toplev.cc b/src/toplev.cc
--- a/src/toplev.cc
+++ b/src/toplev.cc
@@ -671,6 +671,8 @@
 
   OCTAVE_SAFE_CALL (gh_manager::close_all_figures, ());
 
+  OCTAVE_SAFE_CALL (graphics_toolkit::close_all_toolkits, ());
+
   OCTAVE_SAFE_CALL (symbol_table::cleanup, ());
 
   OCTAVE_SAFE_CALL (cleanup_parser, ());

reply via email to

[Prev in Thread] Current Thread [Next in Thread]