# HG changeset patch # User Rik # Date 1381452212 25200 # Node ID 82b1778798d339103e2850f079966551345f1a59 # Parent bd1dd30ed20298c88e85b28f807b3521c0dbf61b 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. diff -r bd1dd30ed202 -r 82b1778798d3 libinterp/corefcn/graphics.cc --- 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");