From cbc93765e3aa08bb2dbf38897a4ad5e6802db5e5 Mon Sep 17 00:00:00 2001 From: Siepert123 Date: Wed, 4 Mar 2026 22:12:41 +0100 Subject: [PATCH] Fix memory leak by listing info pointers --- .../Network/PlatformNetworkManagerStub.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp index 73981533b..bebc9c6c1 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp @@ -697,6 +697,8 @@ void CPlatformNetworkManagerStub::TickSearch() #endif } +std::vector* allocatedServers = NULL; + void CPlatformNetworkManagerStub::SearchForGames() { #ifdef _WINDOWS64 @@ -732,9 +734,18 @@ void CPlatformNetworkManagerStub::SearchForGames() friendsSessions[0].push_back(info); } - //TODO: add file checking for servers.txt #ifdef _WINDOWS64 //Should we have this windows64 only? idk i havent tested so... ifstream ServersTxt("servers.txt"); + + //Memory leak prevention + if (allocatedServers != NULL) { + for (FriendSessionInfo* info : *allocatedServers) { + delete(info); + } + delete(allocatedServers); + } + allocatedServers = new vector; + if (ServersTxt) { string line; @@ -774,6 +785,9 @@ void CPlatformNetworkManagerStub::SearchForGames() info->data.hostPort = stoi(port); info->sessionId = (SessionID)((unsigned __int64)inet_addr(ip.c_str()) | ((unsigned __int64)stoi(port) << 32)); friendsSessions[0].push_back(info); + + //save for later deletion! + allocatedServers->push_back(info); } } ServersTxt.close();