Skip to content

Commit 8485514

Browse files
authored
Merge pull request #902 from saurtron/fix-unsafe-socket-usage-zk
Fix socket leaks and bad error condition checks.
2 parents 2ab631f + 0ba73a4 commit 8485514

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

LuaMenu/widgets/zk_loopback.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ function SendCommand(cmdName, args)
4848
end
4949

5050
local function SocketConnect(host, port)
51+
if client then
52+
client:close()
53+
end
5154
client=socket.tcp()
5255
client:settimeout(0)
5356
res, err = client:connect(host, port)
54-
if not res and not res=="timeout" then
57+
if not res and err ~= "timeout" then
5558
Echo("Error in connect wrapper: "..err)
5659
return false
5760
end

libs/liblobby/lobby/interface_shared.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function Interface:Disconnect()
6161
self.finishedConnecting = false
6262
if self.client then
6363
self.client:close()
64+
self.client = nil
6465
end
6566
self:_OnDisconnected(nil, true)
6667
end

libs/spring-launcher/luaui/widgets/api_spring_launcher.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ local function explode(div,str)
8989
end
9090

9191
function widget:SocketConnect()
92+
if client then
93+
client:close()
94+
end
9295
client = socket.tcp()
9396
client:settimeout(0)
9497
local res, err = client:connect(host, port)
95-
if not res and not res == "timeout" then
98+
if not res and err ~= "timeout" then
99+
client:close()
100+
client = nil
96101
widgetHandler:RemoveWidget(self)
97102
Spring.Log(LOG_SECTION, LOG.ERROR, "Error in connect launcher: " .. err)
98103
return false

0 commit comments

Comments
 (0)