Skip to content

Commit

Permalink
tx: just close file once in WriteTo function
Browse files Browse the repository at this point in the history
WriteTo function closes file twice in normal path previously.
  • Loading branch information
lorneli committed Sep 13, 2017
1 parent 4ff482b commit 53a930f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ func (tx *Tx) WriteTo(w io.Writer) (n int64, err error) {
if err != nil {
return 0, err
}
defer func() { _ = f.Close() }()
defer func() {
if cerr := f.Close(); err == nil {
err = cerr
}
}()

// Generate a meta page. We use the same page data for both meta pages.
buf := make([]byte, tx.db.pageSize)
Expand Down Expand Up @@ -356,7 +360,7 @@ func (tx *Tx) WriteTo(w io.Writer) (n int64, err error) {
return n, err
}

return n, f.Close()
return n, nil
}

// CopyFile copies the entire database to file at the given path.
Expand Down

0 comments on commit 53a930f

Please sign in to comment.