Skip to content

Commit

Permalink
Merge pull request #80 from pin/fd-leak-fix-fix
Browse files Browse the repository at this point in the history
Fix sender FD leak fix
  • Loading branch information
pin authored Jul 20, 2022
2 parents b0f7c38 + e77a42b commit 7416eb4
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func (s *sender) ReadFrom(r io.Reader) (n int64, err error) {
r = netascii.ToReader(r)
}
defer func() {
s.conn.close()
s.conn = nil
if s.conn != nil {
s.conn.close()
s.conn = nil
}
}()
if s.opts != nil {
// check that tsize is set
Expand Down Expand Up @@ -260,15 +262,15 @@ func (s *sender) sendDatagram(l int) (*net.UDPAddr, error) {

func (s *sender) buildTransferStats() TransferStats {
return TransferStats{
RemoteAddr: s.addr.IP,
Filename: s.filename,
Tid: s.tid,
RemoteAddr: s.addr.IP,
Filename: s.filename,
Tid: s.tid,
SenderAnticipateEnabled: s.sendA.enabled,
Mode: s.mode,
Opts: s.opts,
Duration: time.Now().Sub(s.startTime),
DatagramsSent: s.datagramsSent,
DatagramsAcked: s.datagramsAcked,
Mode: s.mode,
Opts: s.opts,
Duration: time.Now().Sub(s.startTime),
DatagramsSent: s.datagramsSent,
DatagramsAcked: s.datagramsAcked,
}
}

Expand Down

0 comments on commit 7416eb4

Please sign in to comment.