Skip to content

Commit

Permalink
tests: fix a few fd leaks
Browse files Browse the repository at this point in the history
We relied on the finalizer to close a few fds.
For some reason, this did not cause problems on Linux,
but on MacOS, it causes unmount failures:

umount(/private/tmp/gocryptfs-test-parent/194654785/default-plain): Resource busy -- try 'diskutil unmount'
  • Loading branch information
rfjakob committed Mar 5, 2018
1 parent 6c172dc commit 3064d72
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/defaults/diriv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestDirIVRace(t *testing.T) {
for {
// Keep dir2 in the diriv cache
fd, err2 := os.Open(file2)
if err2 != nil {
if err2 == nil {
fd.Close()
}
if stop {
Expand Down
2 changes: 2 additions & 0 deletions tests/defaults/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestOpenTruncateRead(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer writeFd.Close()
abc := []byte("abc")
_, err = writeFd.WriteAt(abc, 0)
if err != nil {
Expand All @@ -61,6 +62,7 @@ func TestOpenTruncateRead(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer readFd.Close()
content := make([]byte, 3)
_, err = readFd.ReadAt(content, 0)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tests/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,12 @@ func TestRmwRace(t *testing.T) {
if err != nil {
t.Fatalf("file create failed")
}
defer f1.Close()
f2, err := os.Create(fn)
if err != nil {
t.Fatalf("file create failed")
}
defer f2.Close()

oldBlock := bytes.Repeat([]byte("o"), 4096)

Expand Down

0 comments on commit 3064d72

Please sign in to comment.