From 90e615679c88f6d306a4aef56eaa44f7e871b7aa Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Mon, 12 Sep 2011 14:31:11 -0600 Subject: [PATCH] Fix a bug in BLayout::AddItem() where the right conditions + an error would have caused the wrongful removal of a BView from its parent. --- src/kits/interface/Layout.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/kits/interface/Layout.cpp b/src/kits/interface/Layout.cpp index 58fccb85be..0b168af906 100644 --- a/src/kits/interface/Layout.cpp +++ b/src/kits/interface/Layout.cpp @@ -162,10 +162,14 @@ BLayout::AddItem(int32 index, BLayoutItem* item) // if the item refers to a BView, we make sure it is added to the parent // view BView* view = item->View(); - AutoDeleter remover(view); - if (view && view->fParent != fTarget && !fTarget->_AddChild(view, NULL)) { - remover.Detach(); // view wasn't added - return false; + AutoDeleter remover(NULL); + // In case of errors, we don't want to leave this view added where it + // shouldn't be. + if (view && view->fParent != fTarget) { + if (!fTarget->_AddChild(view, NULL)) + return false; + else + remover.SetTo(view); } // validate the index