Skip to content

Commit

Permalink
Check for error before deferring to close resource
Browse files Browse the repository at this point in the history
In case of error, returned resource is always nil.
Deference it only when call was successful

Closes #113
  • Loading branch information
rkosegi committed Aug 29, 2022
1 parent 2b94619 commit 742114d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,21 @@ func UDPRoutine(name string, decodeFunc decoder.DecoderFunc, workers int, addr s

if sockReuse {
pconn, err := reuseport.ListenPacket("udp", addrUDP.String())
defer pconn.Close()
if err != nil {
return err
}
defer pconn.Close()
var ok bool
udpconn, ok = pconn.(*net.UDPConn)
if !ok {
return err
}
} else {
udpconn, err = net.ListenUDP("udp", &addrUDP)
defer udpconn.Close()
if err != nil {
return err
}
defer udpconn.Close()
}

payload := make([]byte, 9000)
Expand Down

0 comments on commit 742114d

Please sign in to comment.