1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-26 13:48:59 +08:00

[common]: fix potential leak on Sleep.

This commit is contained in:
shirou 2023-05-28 12:32:10 +00:00
parent 03ae19bea8
commit 3e789a459a

View File

@ -11,6 +11,9 @@ func Sleep(ctx context.Context, interval time.Duration) error {
timer := time.NewTimer(interval)
select {
case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}
return ctx.Err()
case <-timer.C:
return nil