Skip to content

Commit

Permalink
Merge pull request #2469 from aruneshpa/topic/aruneshpa/issue-2443
Browse files Browse the repository at this point in the history
Protect FileProvider.files to avoid concurrent access
  • Loading branch information
dougm committed May 28, 2021
2 parents bf423a5 + 8cbe64c commit c07e44a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion vim25/debug/file.go
Expand Up @@ -20,13 +20,16 @@ import (
"io"
"os"
"path"
"sync"
)

// FileProvider implements a debugging provider that creates a real file for
// every call to NewFile. It maintains a list of all files that it creates,
// such that it can close them when its Flush function is called.
type FileProvider struct {
Path string
Path string

mu sync.Mutex
files []*os.File
}

Expand All @@ -36,12 +39,16 @@ func (fp *FileProvider) NewFile(p string) io.WriteCloser {
panic(err)
}

fp.mu.Lock()
defer fp.mu.Unlock()
fp.files = append(fp.files, f)

return NewFileWriterCloser(f, p)
}

func (fp *FileProvider) Flush() {
fp.mu.Lock()
defer fp.mu.Unlock()
for _, f := range fp.files {
f.Close()
}
Expand Down

0 comments on commit c07e44a

Please sign in to comment.