changeset 17626:82b1778798d3

Fix segfault when setting object parent to be object itself (bug #37927). * libinterp/corefcn/graphics.cc(set_parent): Check that the new parent handle is not the same as the object itself.
author Rik <rik@octave.org>
date Thu, 10 Oct 2013 17:43:32 -0700
parents bd1dd30ed202
children 811019b9ef57
files libinterp/corefcn/graphics.cc
diffstat 1 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Thu Oct 10 17:42:02 2013 -0700
+++ b/libinterp/corefcn/graphics.cc	Thu Oct 10 17:43:32 2013 -0700
@@ -2738,20 +2738,27 @@
 
   if (! error_state)
     {
-      new_parent = gh_manager::lookup (tmp);
-
-      if (new_parent.ok ())
-        {
-          graphics_object parent_obj = gh_manager::get_object (get_parent ());
-
-          parent_obj.remove_child (__myhandle__);
-
-          parent = new_parent.as_octave_value ();
-
-          ::adopt (parent.handle_value (), __myhandle__);
-        }
+      if (tmp == __myhandle__)
+        error ("set: can not set object parent to be object itself");
       else
-        error ("set: invalid graphics handle (= %g) for parent", tmp);
+        {
+          new_parent = gh_manager::lookup (tmp);
+
+          if (new_parent.ok ())
+            {
+              graphics_object parent_obj;
+
+              parent_obj = gh_manager::get_object (get_parent ());
+
+              parent_obj.remove_child (__myhandle__);
+
+              parent = new_parent.as_octave_value ();
+
+              ::adopt (parent.handle_value (), __myhandle__);
+            }
+          else
+            error ("set: invalid graphics handle (= %g) for parent", tmp);
+        }
     }
   else
     error ("set: expecting parent to be a graphics handle");