From 31632c4fbba3138a4c02668c25d095c6e23b8f68 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 4 Jul 2020 15:53:36 +0200 Subject: [PATCH] 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. --- tests/sizers/boxsizer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/sizers/boxsizer.cpp b/tests/sizers/boxsizer.cpp index 575fdcd3b3..3bf4d6aba9 100644 --- a/tests/sizers/boxsizer.cpp +++ b/tests/sizers/boxsizer.cpp @@ -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 item(new wxSizerItem(10, 10, 0, f)); \ + sizer->Add(item.get()); \ + item.release() \ ) #define ASSERT_SIZER_INCOMPATIBLE_FLAGS(f1, f2) \