From f98f5ca48b29cf94d796b90b4367979545ac9a31 Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Thu, 1 Dec 2011 19:08:56 -0700 Subject: [PATCH] Fix bug in BView::RemoveSelf() that lead to a segfault. Once again, the BObjectList removal behaviour leads to a null dereference. It's my fault of course, but there you have it. Comments have been included for future devs. --- src/kits/interface/View.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index a37d5bb4a5..d7fed3fbc5 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -4023,10 +4023,13 @@ bool BView::RemoveSelf() { if (fParent && fParent->fLayoutData->fLayout) { - int32 itemCount = fLayoutData->fLayoutItems.CountItems(); - for (int32 i = 0; i < itemCount; i++) { - BLayoutItem* item = fLayoutData->fLayoutItems.ItemAt(i); + int32 itemsRemaining = fLayoutData->fLayoutItems.CountItems(); + while (itemsRemaining-- > 0) { + BLayoutItem* item = fLayoutData->fLayoutItems.ItemAt(0); + // always remove item at index 0, since items are shuffled + // downwards by BObjectList item->Layout()->RemoveItem(item); + // removes item from fLayoutItems list delete item; } }