From 413c05ea8548c0a35249b482cf16965af6f6acbc Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 13 Oct 2020 10:41:57 +0700 Subject: [PATCH] Fix wxAcceleratorEntry memory leaks in the menu test Use wxScopedPtr to ensure that all the test accelerator entries are destroyed instead of just being leaked. --- tests/menu/accelentry.cpp | 11 ++++++----- tests/menu/menu.cpp | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/menu/accelentry.cpp b/tests/menu/accelentry.cpp index 0f809da446..652c594b69 100644 --- a/tests/menu/accelentry.cpp +++ b/tests/menu/accelentry.cpp @@ -17,6 +17,7 @@ #endif // WX_PRECOMP #include "wx/accel.h" +#include "wx/scopedptr.h" namespace { @@ -35,11 +36,11 @@ void CheckAccelEntry(const wxAcceleratorEntry& accel, int keycode, int flags) */ TEST_CASE( "wxAcceleratorEntry::Create", "[accelentry]" ) { - wxAcceleratorEntry* pa; + wxScopedPtr pa; SECTION( "Correct behavior" ) { - pa = wxAcceleratorEntry::Create("Foo\tCtrl+Z"); + pa.reset( wxAcceleratorEntry::Create("Foo\tCtrl+Z") ); CHECK( pa ); CHECK( pa->IsOk() ); @@ -48,21 +49,21 @@ TEST_CASE( "wxAcceleratorEntry::Create", "[accelentry]" ) SECTION( "Tab missing" ) { - pa = wxAcceleratorEntry::Create("Shift-Q"); + pa.reset( wxAcceleratorEntry::Create("Shift-Q") ); CHECK( !pa ); } SECTION( "No accelerator key specified" ) { - pa = wxAcceleratorEntry::Create("bloordyblop"); + pa.reset( wxAcceleratorEntry::Create("bloordyblop") ); CHECK( !pa ); } SECTION( "Display name parsing" ) { - pa = wxAcceleratorEntry::Create("Test\tBackSpace"); + pa.reset( wxAcceleratorEntry::Create("Test\tBackSpace") ); CHECK( pa ); CHECK( pa->IsOk() ); diff --git a/tests/menu/menu.cpp b/tests/menu/menu.cpp index a99b053767..6ce4a58664 100644 --- a/tests/menu/menu.cpp +++ b/tests/menu/menu.cpp @@ -20,6 +20,7 @@ #endif // WX_PRECOMP #include "wx/menu.h" +#include "wx/scopedptr.h" #include "wx/translation.h" #include "wx/uiaction.h" @@ -624,7 +625,9 @@ namespace void VerifyAccelAssigned( wxString labelText, int keycode ) { - wxAcceleratorEntry* entry = wxAcceleratorEntry::Create( labelText ); + const wxScopedPtr entry( + wxAcceleratorEntry::Create( labelText ) + ); CHECK( entry ); CHECK( entry->GetKeyCode() == keycode );