Skip to content

Commit

Permalink
fix: memory leak (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbqvq authored Oct 4, 2024
1 parent 2ffcdaf commit da3a437
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,10 @@ func (l *Listener) Accept() (net.Conn, error) {
func (l *Listener) AcceptKCP() (*UDPSession, error) {
var timeout <-chan time.Time
if tdeadline, ok := l.rd.Load().(time.Time); ok && !tdeadline.IsZero() {
timeout = time.After(time.Until(tdeadline))
timer := time.NewTimer(time.Until(tdeadline))
defer timer.Stop()

timeout = timer.C
}

select {
Expand Down
4 changes: 3 additions & 1 deletion timedsched.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ func NewTimedSched(parallel int) *TimedSched {

// sched is a goroutine to schedule and execute timed tasks.
func (ts *TimedSched) sched() {
var tasks timedFuncHeap
timer := time.NewTimer(0)
defer timer.Stop()

var tasks timedFuncHeap
drained := false
for {
select {
Expand Down

0 comments on commit da3a437

Please sign in to comment.