Skip to content

Commit

Permalink
Merge pull request #1430 from davidnewhall/master
Browse files Browse the repository at this point in the history
Fix 'send on closed channel' bug with windows disks
  • Loading branch information
shirou authored Mar 19, 2023
2 parents 06a922c + 3a88ef2 commit 27c8bfa
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 27c8bfa

Please sign in to comment.