From 3dec092dff02570f6b99e9ab42f1b81a030c6b9d Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 13 Oct 2020 15:49:32 +0700 Subject: [PATCH] Fix memory leak in wxGridSizer::Insert() if an assert in it fails This avoids another memory leak in the test suite, which intentionally triggers an assert in this function. --- src/common/sizer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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