Fix wxMemoryFSHandler memory leaks in wxFileSystem unit test

Use wxScopedPtr<> to ensure the handlers we use get freed.
This commit is contained in:
Ilya Sinitsyn 2020-10-14 08:19:53 +07:00 committed by Vadim Zeitlin
parent 987758eb97
commit 10c68e9973

View File

@ -22,6 +22,7 @@
#if wxUSE_FILESYSTEM #if wxUSE_FILESYSTEM
#include "wx/fs_mem.h" #include "wx/fs_mem.h"
#include "wx/scopedptr.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// helpers // helpers
@ -186,16 +187,16 @@ TEST_CASE("wxFileSystem::MemoryFSHandler", "[filesys][memoryfshandler][find]")
AutoMemoryFSHandler() AutoMemoryFSHandler()
: m_handler(new wxMemoryFSHandler()) : m_handler(new wxMemoryFSHandler())
{ {
wxFileSystem::AddHandler(m_handler); wxFileSystem::AddHandler(m_handler.get());
} }
~AutoMemoryFSHandler() ~AutoMemoryFSHandler()
{ {
wxFileSystem::RemoveHandler(m_handler); wxFileSystem::RemoveHandler(m_handler.get());
} }
private: private:
wxMemoryFSHandler* const m_handler; wxScopedPtr<wxMemoryFSHandler> const m_handler;
} autoMemoryFSHandler; } autoMemoryFSHandler;
wxMemoryFSHandler::AddFile("foo.txt", "foo contents"); wxMemoryFSHandler::AddFile("foo.txt", "foo contents");