Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Close socket immediately after error in if_nametoindex()
Immediately close the socket used internally by syscall.util.if_nametoindex(),
right after the lower-level implementation call notifies of an error. This avoids
letting the socket be garbage-collected later on.
  • Loading branch information
aperezdc committed Feb 9, 2016
1 parent 96c0286 commit 8915a83
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion syscall/linux/util.lua
Expand Up @@ -46,7 +46,10 @@ function util.if_nametoindex(name) -- standard function in some libc versions
local s, err = S.socket(c.AF.LOCAL, c.SOCK.STREAM, 0)
if not s then return nil, err end
local i, err = if_nametoindex(name, s)
if not i then return nil, err end
if not i then
S.close(s)
return nil, err
end
local ok, err = S.close(s)
if not ok then return nil, err end
return i
Expand Down

0 comments on commit 8915a83

Please sign in to comment.