Fix memory leaks in BoxSizer::IncompatibleFlags test case

The sizer item allocated by wxSizer::Add() was leaked if an exception
was thrown due to the use of invalid flags, resulting in tons of memory
leak reports from the leak sanitizer.

Fix them by using wxScopedPtr<> for this item and releasing it only if
adding the item to the sizer (unexpectedly) did not throw.

No real changes.
This commit is contained in:
Vadim Zeitlin 2020-07-04 15:53:36 +02:00
parent 81e3760e4a
commit 31632c4fbb

View File

@ -24,6 +24,8 @@
#include "asserthelper.h"
#include "wx/scopedptr.h"
// ----------------------------------------------------------------------------
// test fixture
// ----------------------------------------------------------------------------
@ -367,7 +369,9 @@ TEST_CASE_METHOD(BoxSizerTestCase, "BoxSizer::IncompatibleFlags", "[sizer]")
#define ASSERT_SIZER_INVALID_FLAGS(f, msg) \
WX_ASSERT_FAILS_WITH_ASSERT_MESSAGE( \
"Expected assertion not generated for " msg, \
sizer->Add(10, 10, 0, f) \
wxScopedPtr<wxSizerItem> item(new wxSizerItem(10, 10, 0, f)); \
sizer->Add(item.get()); \
item.release() \
)
#define ASSERT_SIZER_INCOMPATIBLE_FLAGS(f1, f2) \