Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'send on closed channel' bug with windows disks #1430

Merged
merged 1 commit into from
Mar 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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