Skip to content

Commit

Permalink
close channel in function that sends to it
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Mar 14, 2023
1 parent c7c548d commit 3a88ef2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions disk/disk_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bytes"
"context"
"fmt"
"sync"
"syscall"
"unsafe"

Expand Down Expand Up @@ -90,12 +91,20 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
var ret []PartitionStat
retChan := make(chan []PartitionStat)
errChan := make(chan error)
defer close(retChan)
defer close(errChan)

lpBuffer := make([]byte, 254)

var waitgrp sync.WaitGroup
waitgrp.Add(1)
defer waitgrp.Done()

f := func() {
defer func() {
waitgrp.Wait()
// fires when this func and the outside func finishes.
close(errChan)
close(retChan)
}()

diskret, _, err := procGetLogicalDriveStringsW.Call(
uintptr(len(lpBuffer)),
uintptr(unsafe.Pointer(&lpBuffer[0])))
Expand Down

0 comments on commit 3a88ef2

Please sign in to comment.