diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index 0a96b13eed..b469097468 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -32,6 +32,7 @@ #include "wx/vector.h" #include "wx/listimpl.cpp" #include "wx/private/window.h" +#include "wx/scopedptr.h" //--------------------------------------------------------------------------- @@ -1479,6 +1480,9 @@ wxGridSizer::wxGridSizer( int rows, int cols, const wxSize& gap ) wxSizerItem *wxGridSizer::DoInsert(size_t index, wxSizerItem *item) { + // Ensure that the item will be deleted in case of exception. + wxScopedPtr scopedItem( item ); + // if only the number of columns or the number of rows is specified for a // sizer, arbitrarily many items can be added to it but if both of them are // fixed, then the sizer can't have more than that many items -- check for @@ -1519,7 +1523,7 @@ wxSizerItem *wxGridSizer::DoInsert(size_t index, wxSizerItem *item) ); } - return wxSizer::DoInsert(index, item); + return wxSizer::DoInsert( index, scopedItem.release() ); } int wxGridSizer::CalcRowsCols(int& nrows, int& ncols) const