Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix socket leaks and bad error condition checks. #902

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion LuaMenu/widgets/zk_loopback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libs/liblobby/lobby/interface_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion libs/spring-launcher/luaui/widgets/api_spring_launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down