Core/Misc: Replace shared_ptr with unique_ptr with deleter for cleanups in main() functions

This commit is contained in:
Shauren
2024-04-04 21:31:22 +02:00
parent 038f995ad6
commit 7df138ba2b
2 changed files with 36 additions and 31 deletions

View File

@@ -35,6 +35,7 @@
#include "IpNetwork.h"
#include "Locales.h"
#include "LoginRESTService.h"
#include "Memory.h"
#include "MySQLThreading.h"
#include "OpenSSLCrypto.h"
#include "ProcessPriority.h"
@@ -102,9 +103,11 @@ int main(int argc, char** argv)
if (vm.count("help") || vm.count("version"))
return 0;
uint32 dummy = 0;
GOOGLE_PROTOBUF_VERIFY_VERSION;
std::shared_ptr<void> protobufHandle(nullptr, [](void*) { google::protobuf::ShutdownProtobufLibrary(); });
auto protobufHandle = Trinity::make_unique_ptr_with_deleter(&dummy, [](void*) { google::protobuf::ShutdownProtobufLibrary(); });
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
if (winServiceAction == "install")
@@ -161,7 +164,7 @@ int main(int argc, char** argv)
OpenSSLCrypto::threadsSetup(boost::dll::program_location().remove_filename());
std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });
auto opensslHandle = Trinity::make_unique_ptr_with_deleter(&dummy, [](void*) { OpenSSLCrypto::threadsCleanup(); });
// bnetserver PID file creation
std::string pidFile = sConfigMgr->GetStringDefault("PidFile", "");
@@ -186,7 +189,7 @@ int main(int argc, char** argv)
if (!StartDB())
return 1;
std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
auto dbHandle = Trinity::make_unique_ptr_with_deleter(&dummy, [](void*) { StopDB(); });
if (vm.count("update-databases-only"))
return 0;
@@ -214,7 +217,7 @@ int main(int argc, char** argv)
return 1;
}
std::shared_ptr<void> sLoginServiceHandle(nullptr, [](void*) { sLoginService.StopNetwork(); });
auto sLoginServiceHandle = Trinity::make_unique_ptr_with_deleter(&dummy, [](void*) { sLoginService.StopNetwork(); });
// Start the listening port (acceptor) for auth connections
int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119);
@@ -227,7 +230,7 @@ int main(int argc, char** argv)
// Get the list of realms for the server
sRealmList->Initialize(*ioContext, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10));
std::shared_ptr<void> sRealmListHandle(nullptr, [](void*) { sRealmList->Close(); });
auto sRealmListHandle = Trinity::make_unique_ptr_with_deleter(&dummy, [](void*) { sRealmList->Close(); });
std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
@@ -237,7 +240,7 @@ int main(int argc, char** argv)
return 1;
}
std::shared_ptr<void> sSessionMgrHandle(nullptr, [](void*) { sSessionMgr.StopNetwork(); });
auto sSessionMgrHandle = Trinity::make_unique_ptr_with_deleter(&dummy, [](void*) { sSessionMgr.StopNetwork(); });
// Set signal handlers
boost::asio::signal_set signals(*ioContext, SIGINT, SIGTERM);