Associate the window with the sizer in wxSizer::Replace()
If wxSizerItem passed to Replace() contains a window, the window must be associated with the sizer to ensure that it is uncoupled from it when it is destroyed. Add a simple test which resulted in a use-after-free before but passes now.
This commit is contained in:
@@ -883,6 +883,9 @@ bool wxSizer::Replace( size_t old, wxSizerItem *newitem )
|
|||||||
|
|
||||||
delete item;
|
delete item;
|
||||||
|
|
||||||
|
if (wxWindow* const w = newitem->GetWindow())
|
||||||
|
w->SetContainingSizer(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -444,3 +444,9 @@ TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::IncompatibleFlags", "[sizer]")
|
|||||||
#undef ASSERT_SIZER_INCOMPATIBLE_FLAGS
|
#undef ASSERT_SIZER_INCOMPATIBLE_FLAGS
|
||||||
#undef ASSERT_SIZER_INVALID_FLAGS
|
#undef ASSERT_SIZER_INVALID_FLAGS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::Replace", "[sizer]")
|
||||||
|
{
|
||||||
|
m_sizer->AddSpacer(1);
|
||||||
|
m_sizer->Replace(0, new wxSizerItem(new wxWindow(m_win, wxID_ANY)));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user