Skip to content

Commit

Permalink
fix race and parityshard leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Nov 7, 2019
1 parent 68589db commit 2ed35ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fec.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (dec *fecDecoder) decode(in fecPacket) (recovered [][]byte) {
dlen := len(shards[k])
shards[k] = shards[k][:maxlen]
copy(shards[k][dlen:], dec.zeros)
} else {
} else if k < dec.dataShards {
shards[k] = xmitBuf.Get().([]byte)[:0]
}
}
Expand Down
3 changes: 2 additions & 1 deletion sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,10 @@ func (s *UDPSession) kcpInput(data []byte) {
if f.flag() == typeParity {
fecParityShards++
}
recovers := s.fecDecoder.decode(f)

// lock
s.mu.Lock()
recovers := s.fecDecoder.decode(f)
if f.flag() == typeData {
if ret := s.kcp.Input(data[fecHeaderSizePlus2:], true, s.ackNoDelay); ret != 0 {
kcpInErrors++
Expand Down

0 comments on commit 2ed35ac

Please sign in to comment.