diff --git a/deps/protobuf b/deps/protobuf index 40ff94eb..18a9140f 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 40ff94ebef494e2e16107ce2965215ae67c031c1 +Subproject commit 18a9140f3308272313a9642af58ab0051ac09fd2 diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 753d31eb..fdc6369b 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -80,15 +80,13 @@ namespace Components Localization::Set("MPUI_SECURITY_INCREASE_MESSAGE", Utils::VA("Increasing security level from %d to %d (est. %s)", Auth::GetSecurityLevel(), Auth::TokenContainer.targetLevel, Utils::FormatTimeSpan(static_cast(mseconds)).data())); } - else if(Auth::TokenContainer.thread) + else { - if (Auth::TokenContainer.thread->joinable()) + if (Auth::TokenContainer.thread.joinable()) { - Auth::TokenContainer.thread->join(); + Auth::TokenContainer.thread.join(); } - delete Auth::TokenContainer.thread; - Auth::TokenContainer.thread = nullptr; Auth::TokenContainer.generating = false; Auth::StoreKey(); @@ -208,7 +206,7 @@ namespace Components Command::Execute("openmenu security_increase_popmenu", true); // Start thread - Auth::TokenContainer.thread = new std::thread([&level] () + Auth::TokenContainer.thread = std::thread([&level] () { Auth::TokenContainer.generating = true; Auth::TokenContainer.hashes = 0; @@ -293,7 +291,6 @@ namespace Components { Auth::TokenContainer.cancel = false; Auth::TokenContainer.generating = false; - Auth::TokenContainer.thread = nullptr; Localization::Set("MPUI_SECURITY_INCREASE_MESSAGE", ""); @@ -428,15 +425,9 @@ namespace Components Auth::TokenContainer.generating = false; // Terminate thread - if (Auth::TokenContainer.thread) + if (Auth::TokenContainer.thread.joinable()) { - if (Auth::TokenContainer.thread->joinable()) - { - Auth::TokenContainer.thread->join(); - } - - delete Auth::TokenContainer.thread; - Auth::TokenContainer.thread = nullptr; + Auth::TokenContainer.thread.join(); } Auth::StoreKey(); diff --git a/src/Components/Modules/Auth.hpp b/src/Components/Modules/Auth.hpp index 77bb3385..be90a337 100644 --- a/src/Components/Modules/Auth.hpp +++ b/src/Components/Modules/Auth.hpp @@ -40,7 +40,7 @@ namespace Components { bool cancel; bool generating; - std::thread* thread; + std::thread thread; uint32_t targetLevel; int startTime; std::string command; diff --git a/src/Components/Modules/Discovery.cpp b/src/Components/Modules/Discovery.cpp index 75937f19..14b5c207 100644 --- a/src/Components/Modules/Discovery.cpp +++ b/src/Components/Modules/Discovery.cpp @@ -2,7 +2,7 @@ namespace Components { - Discovery::Container Discovery::DiscoveryContainer = { false, false, nullptr }; + Discovery::Container Discovery::DiscoveryContainer = { false, false, std::thread() }; void Discovery::Perform() { @@ -16,7 +16,7 @@ namespace Components Discovery::DiscoveryContainer.Perform = false; Discovery::DiscoveryContainer.Terminate = false; - Discovery::DiscoveryContainer.Thread = new std::thread([] () + Discovery::DiscoveryContainer.Thread = std::thread([] () { while (!Discovery::DiscoveryContainer.Terminate) { @@ -85,11 +85,9 @@ namespace Components Discovery::DiscoveryContainer.Perform = false; Discovery::DiscoveryContainer.Terminate = true; - if (Discovery::DiscoveryContainer.Thread) + if (Discovery::DiscoveryContainer.Thread.joinable()) { - Discovery::DiscoveryContainer.Thread->join(); - delete Discovery::DiscoveryContainer.Thread; - Discovery::DiscoveryContainer.Thread = nullptr; + Discovery::DiscoveryContainer.Thread.join(); } } } diff --git a/src/Components/Modules/Discovery.hpp b/src/Components/Modules/Discovery.hpp index 3a8b8a5c..bb5775b2 100644 --- a/src/Components/Modules/Discovery.hpp +++ b/src/Components/Modules/Discovery.hpp @@ -14,7 +14,7 @@ namespace Components { bool Perform; bool Terminate; - std::thread* Thread; + std::thread Thread; std::string Challenge; }; diff --git a/src/Components/Modules/IPCPipe.cpp b/src/Components/Modules/IPCPipe.cpp index 2f0ad7b5..1215e8c2 100644 --- a/src/Components/Modules/IPCPipe.cpp +++ b/src/Components/Modules/IPCPipe.cpp @@ -7,7 +7,7 @@ namespace Components #pragma region Pipe - Pipe::Pipe() : mType(IPCTYPE_NONE), ReconnectAttempt(0), hPipe(INVALID_HANDLE_VALUE), mThread(0), ConnectCallback(0), mThreadAttached(false) + Pipe::Pipe() : mType(IPCTYPE_NONE), ReconnectAttempt(0), hPipe(INVALID_HANDLE_VALUE), ConnectCallback(0), mThreadAttached(false) { this->Destroy(); } @@ -66,7 +66,7 @@ namespace Components if (!Loader::PerformingUnitTests()) { this->mThreadAttached = true; - this->mThread = new std::thread(Pipe::ReceiveThread, this); + this->mThread = std::thread(Pipe::ReceiveThread, this); } Logger::Print("Pipe successfully created\n"); @@ -117,17 +117,13 @@ namespace Components this->mThreadAttached = false; - if (this->mThread) + if (this->mThread.joinable()) { Logger::Print("Terminating pipe thread...\n"); - this->mThread->join(); + this->mThread.join(); Logger::Print("Pipe thread terminated.\n"); - - delete this->mThread; - - this->mThread = 0; } } diff --git a/src/Components/Modules/IPCPipe.hpp b/src/Components/Modules/IPCPipe.hpp index 73ce18ab..cb433278 100644 --- a/src/Components/Modules/IPCPipe.hpp +++ b/src/Components/Modules/IPCPipe.hpp @@ -41,7 +41,7 @@ namespace Components std::map PacketCallbacks; HANDLE hPipe; - std::thread* mThread; + std::thread mThread; bool mThreadAttached; Type mType; diff --git a/src/Components/Modules/News.cpp b/src/Components/Modules/News.cpp index e6756440..5468be91 100644 --- a/src/Components/Modules/News.cpp +++ b/src/Components/Modules/News.cpp @@ -4,20 +4,16 @@ namespace Components { - std::thread* News::Thread = nullptr; + std::thread News::Thread; bool News::UnitTest() { bool result = true; - if (News::Thread) + if (News::Thread.joinable()) { Logger::Print("Awaiting thread termination...\n"); - - News::Thread->join(); - delete News::Thread; - - News::Thread = nullptr; + News::Thread.join(); if (!strlen(Localization::Get("MPUI_CHANGELOG_TEXT")) || Localization::Get("MPUI_CHANGELOG_TEXT") == std::string("Loading...")) { @@ -48,7 +44,7 @@ namespace Components Localization::Set("MPUI_CHANGELOG_TEXT", "Loading..."); Localization::Set("MPUI_MOTD_TEXT", NEWS_MOTD_DEFUALT); - News::Thread = new std::thread([] () + News::Thread = std::thread([] () { Localization::Set("MPUI_CHANGELOG_TEXT", Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/changelog.txt").SetTimeout(5000)->Get().data()); @@ -65,12 +61,9 @@ namespace Components News::~News() { - if (News::Thread) + if (News::Thread.joinable()) { - News::Thread->join(); - delete News::Thread; - - News::Thread = nullptr; + News::Thread.join(); } } } diff --git a/src/Components/Modules/News.hpp b/src/Components/Modules/News.hpp index 54ed7151..a2f3ee8c 100644 --- a/src/Components/Modules/News.hpp +++ b/src/Components/Modules/News.hpp @@ -9,6 +9,6 @@ namespace Components bool UnitTest(); private: - static std::thread* Thread; + static std::thread Thread; }; }