From 9cd9da4a5360028bab32bb7f04d95e67e895cc0d Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Thu, 17 Feb 2022 07:27:41 -0800 Subject: [PATCH] fix(CI): Fix memory leak in core_test Causes false positives when running tests with ASAN --- test/core/core_test.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/core/core_test.cpp b/test/core/core_test.cpp index ee21632e7..7480a61b5 100644 --- a/test/core/core_test.cpp +++ b/test/core/core_test.cpp @@ -22,13 +22,15 @@ #include "src/core/icoresettings.h" #include "src/net/bootstrapnodeupdater.h" #include "src/model/ibootstraplistgenerator.h" +#include "src/persistence/settings.h" #include #include #include #include -#include + #include +#include Q_DECLARE_METATYPE(QList) @@ -94,7 +96,7 @@ private slots: private: /* Test Variables */ Core::ToxCoreErrors* err = nullptr; - MockSettings* settings; + std::unique_ptr settings; QByteArray savedata{}; ToxCorePtr test_core; }; @@ -106,7 +108,7 @@ namespace { void TestCore::startup_without_proxy() { - settings = new MockSettings(); + settings = std::unique_ptr(new MockSettings()); // No proxy settings->setProxyAddr(""); @@ -115,7 +117,7 @@ void TestCore::startup_without_proxy() MockNodeListGenerator nodesGenerator{}; - test_core = Core::makeToxCore(savedata, settings, nodesGenerator, err); + test_core = Core::makeToxCore(savedata, settings.get(), nodesGenerator, err); if (test_core == nullptr) { QFAIL("ToxCore initialisation failed"); @@ -133,8 +135,7 @@ void TestCore::startup_without_proxy() void TestCore::startup_with_invalid_proxy() { - settings = new MockSettings(); - + settings = std::unique_ptr(new MockSettings()); // Test invalid proxy SOCKS5 settings->setProxyAddr("Test"); @@ -143,7 +144,7 @@ void TestCore::startup_with_invalid_proxy() MockNodeListGenerator nodesGenerator{}; - test_core = Core::makeToxCore(savedata, settings, nodesGenerator, err); + test_core = Core::makeToxCore(savedata, settings.get(), nodesGenerator, err); if (test_core != nullptr) { QFAIL("ToxCore initialisation passed with invalid SOCKS5 proxy address"); @@ -155,7 +156,7 @@ void TestCore::startup_with_invalid_proxy() settings->setProxyPort(9985); settings->setProxyType(MockSettings::ProxyType::ptHTTP); - test_core = Core::makeToxCore(savedata, settings, nodesGenerator, err); + test_core = Core::makeToxCore(savedata, settings.get(), nodesGenerator, err); if (test_core != nullptr) { QFAIL("ToxCore initialisation passed with invalid HTTP proxy address");