Skip to content

Commit 3a88ef2

Browse files
committed
close channel in function that sends to it
1 parent c7c548d commit 3a88ef2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

disk/disk_windows.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"context"
99
"fmt"
10+
"sync"
1011
"syscall"
1112
"unsafe"
1213

@@ -90,12 +91,20 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
9091
var ret []PartitionStat
9192
retChan := make(chan []PartitionStat)
9293
errChan := make(chan error)
93-
defer close(retChan)
94-
defer close(errChan)
95-
9694
lpBuffer := make([]byte, 254)
9795

96+
var waitgrp sync.WaitGroup
97+
waitgrp.Add(1)
98+
defer waitgrp.Done()
99+
98100
f := func() {
101+
defer func() {
102+
waitgrp.Wait()
103+
// fires when this func and the outside func finishes.
104+
close(errChan)
105+
close(retChan)
106+
}()
107+
99108
diskret, _, err := procGetLogicalDriveStringsW.Call(
100109
uintptr(len(lpBuffer)),
101110
uintptr(unsafe.Pointer(&lpBuffer[0])))

0 commit comments

Comments
 (0)