From b4cc1ade020665d0ba8f5c5e40c7f4f1ce90ec38 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 19 Apr 2023 12:25:21 -0400 Subject: Common/TraversalClient: Use correct deleter with g_MainNetHost Previously this was using the default deleter (which just calls delete on the pointer), which is incorrect, since the ENetHost instance is allocated through ENet's C API, so we need to use its functions to deallocate the host instead. --- Source/Core/Common/TraversalClient.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'Source/Core/Common/TraversalClient.cpp') diff --git a/Source/Core/Common/TraversalClient.cpp b/Source/Core/Common/TraversalClient.cpp index f3ab481a51..b215e5d269 100644 --- a/Source/Core/Common/TraversalClient.cpp +++ b/Source/Core/Common/TraversalClient.cpp @@ -304,7 +304,7 @@ int ENET_CALLBACK TraversalClient::InterceptCallback(ENetHost* host, ENetEvent* } std::unique_ptr g_TraversalClient; -std::unique_ptr g_MainNetHost; +Common::ENet::ENetHostPtr g_MainNetHost; // The settings at the previous TraversalClient reset - notably, we // need to know not just what port it's on, but whether it was @@ -323,18 +323,18 @@ bool EnsureTraversalClient(const std::string& server, u16 server_port, u16 liste g_OldListenPort = listen_port; ENetAddress addr = {ENET_HOST_ANY, listen_port}; - ENetHost* host = enet_host_create(&addr, // address - 50, // peerCount - NetPlay::CHANNEL_COUNT, // channelLimit - 0, // incomingBandwidth - 0); // outgoingBandwidth + auto host = Common::ENet::ENetHostPtr{enet_host_create(&addr, // address + 50, // peerCount + NetPlay::CHANNEL_COUNT, // channelLimit + 0, // incomingBandwidth + 0)}; // outgoingBandwidth if (!host) { g_MainNetHost.reset(); return false; } host->mtu = std::min(host->mtu, NetPlay::MAX_ENET_MTU); - g_MainNetHost.reset(host); + g_MainNetHost = std::move(host); g_TraversalClient.reset(new TraversalClient(g_MainNetHost.get(), server, server_port)); } return true; -- cgit v1.2.3