From 5ac8412734aaf1733d63da5f020a07608d0e529e Mon Sep 17 00:00:00 2001 From: Saurtron Date: Thu, 28 Nov 2024 12:36:20 +0100 Subject: [PATCH] Fix socket leaks and bad error condition checks. --- LuaMenu/widgets/zk_loopback.lua | 5 ++++- LuaMenu/widgets/zk_replay_launcher.lua | 5 ++++- libs/liblobby/lobby/interface_shared.lua | 1 + libs/spring-launcher/luaui/widgets/api_spring_launcher.lua | 7 ++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/LuaMenu/widgets/zk_loopback.lua b/LuaMenu/widgets/zk_loopback.lua index bc5f52994..24dca775e 100644 --- a/LuaMenu/widgets/zk_loopback.lua +++ b/LuaMenu/widgets/zk_loopback.lua @@ -48,10 +48,13 @@ function SendCommand(cmdName, args) end local function SocketConnect(host, port) + if client then + client:close() + end client=socket.tcp() client:settimeout(0) res, err = client:connect(host, port) - if not res and not res=="timeout" then + if not res and err ~= "timeout" then Echo("Error in connect wrapper: "..err) return false end diff --git a/LuaMenu/widgets/zk_replay_launcher.lua b/LuaMenu/widgets/zk_replay_launcher.lua index cf5e0ab55..4f47cf069 100644 --- a/LuaMenu/widgets/zk_replay_launcher.lua +++ b/LuaMenu/widgets/zk_replay_launcher.lua @@ -86,10 +86,13 @@ end -- initiates a connection to host:port, returns true on success local function SocketConnect(host, port) + if client then + client:close() + end client=socket.tcp() client:settimeout(0) res, err = client:connect(host, port) - if not res and not res=="timeout" then + if not res and err ~= "timeout" then --Echo("Error in connect: "..err) return false end diff --git a/libs/liblobby/lobby/interface_shared.lua b/libs/liblobby/lobby/interface_shared.lua index 9438ea26f..7dd627b76 100644 --- a/libs/liblobby/lobby/interface_shared.lua +++ b/libs/liblobby/lobby/interface_shared.lua @@ -61,6 +61,7 @@ function Interface:Disconnect() self.finishedConnecting = false if self.client then self.client:close() + self.client = nil end self:_OnDisconnected(nil, true) end diff --git a/libs/spring-launcher/luaui/widgets/api_spring_launcher.lua b/libs/spring-launcher/luaui/widgets/api_spring_launcher.lua index a2e7ab95d..cb9cc9e40 100644 --- a/libs/spring-launcher/luaui/widgets/api_spring_launcher.lua +++ b/libs/spring-launcher/luaui/widgets/api_spring_launcher.lua @@ -89,10 +89,15 @@ local function explode(div,str) end function widget:SocketConnect() + if client then + client:close() + end client = socket.tcp() client:settimeout(0) local res, err = client:connect(host, port) - if not res and not res == "timeout" then + if not res and err ~= "timeout" then + client:close() + client = nil widgetHandler:RemoveWidget(self) Spring.Log(LOG_SECTION, LOG.ERROR, "Error in connect launcher: " .. err) return false