mirror of
https://github.com/shirou/gopsutil.git
synced 2025-05-06 19:29:13 +08:00
[common]: fix potential leak on Sleep.
This commit is contained in:
parent
03ae19bea8
commit
3e789a459a
@ -11,6 +11,9 @@ func Sleep(ctx context.Context, interval time.Duration) error {
|
|||||||
timer := time.NewTimer(interval)
|
timer := time.NewTimer(interval)
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
if !timer.Stop() {
|
||||||
|
<-timer.C
|
||||||
|
}
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user