comparison libinterp/corefcn/graphics.cc @ 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 e7692efcbd0d
children 94dd9bba06a0
comparison
equal deleted inserted replaced
17625:bd1dd30ed202 17626:82b1778798d3
2736 2736
2737 graphics_handle new_parent = octave_NaN; 2737 graphics_handle new_parent = octave_NaN;
2738 2738
2739 if (! error_state) 2739 if (! error_state)
2740 { 2740 {
2741 new_parent = gh_manager::lookup (tmp); 2741 if (tmp == __myhandle__)
2742 2742 error ("set: can not set object parent to be object itself");
2743 if (new_parent.ok ())
2744 {
2745 graphics_object parent_obj = gh_manager::get_object (get_parent ());
2746
2747 parent_obj.remove_child (__myhandle__);
2748
2749 parent = new_parent.as_octave_value ();
2750
2751 ::adopt (parent.handle_value (), __myhandle__);
2752 }
2753 else 2743 else
2754 error ("set: invalid graphics handle (= %g) for parent", tmp); 2744 {
2745 new_parent = gh_manager::lookup (tmp);
2746
2747 if (new_parent.ok ())
2748 {
2749 graphics_object parent_obj;
2750
2751 parent_obj = gh_manager::get_object (get_parent ());
2752
2753 parent_obj.remove_child (__myhandle__);
2754
2755 parent = new_parent.as_octave_value ();
2756
2757 ::adopt (parent.handle_value (), __myhandle__);
2758 }
2759 else
2760 error ("set: invalid graphics handle (= %g) for parent", tmp);
2761 }
2755 } 2762 }
2756 else 2763 else
2757 error ("set: expecting parent to be a graphics handle"); 2764 error ("set: expecting parent to be a graphics handle");
2758 } 2765 }
2759 2766