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

The UDPConn should be closed when setUDPSocketOptions returned an error #1226

Closed
nirui opened this issue Feb 24, 2021 · 1 comment · Fixed by #1227
Closed

The UDPConn should be closed when setUDPSocketOptions returned an error #1226

nirui opened this issue Feb 24, 2021 · 1 comment · Fixed by #1227

Comments

@nirui
Copy link
Contributor

nirui commented Feb 24, 2021

Hi all :D

I'm just reading the source code, and discovered a small potential problem here:

dns/server.go

Line 323 in 67bd57d

if e := setUDPSocketOptions(u); e != nil {

The function setUDPSocketOptions above operates on an already-opened UDPConn, so if an error caused an abort action there, the UDPConn must be closed before doing return e.

I think the code should be:

u := l.(*net.UDPConn)
if e := setUDPSocketOptions(u); e != nil {
    u.Close() // Maybe handle this error too? No?
    return e
}
@tmthrgd
Copy link
Collaborator

tmthrgd commented Feb 25, 2021

Yep good catch, feel free to send a PR. There’s no need to handle the error from Close though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants