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

tx.go: just close file once in WriteTo function #44

Merged
merged 1 commit into from
Sep 14, 2017

Conversation

lorneli
Copy link
Contributor

@lorneli lorneli commented Sep 11, 2017

WriteTo function closes file twice in normal path previously.

@codecov-io
Copy link

codecov-io commented Sep 11, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@a4199f8). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #44   +/-   ##
=========================================
  Coverage          ?   85.52%           
=========================================
  Files             ?        9           
  Lines             ?     1851           
  Branches          ?        0           
=========================================
  Hits              ?     1583           
  Misses            ?      159           
  Partials          ?      109
Impacted Files Coverage Δ
tx.go 76.14% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4199f8...53a930f. Read the comment docs.

tx.go Outdated
@@ -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 err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will still double close when return n, f.Close() has an error. Try return n, nil and

defer func() {
    if cerr := f.Close(); err == nil {
        err = cerr
    }
}

WriteTo function closes file twice in normal path previously.
@xiang90
Copy link
Contributor

xiang90 commented Sep 13, 2017

lgtm

@heyitsanthony heyitsanthony merged commit 2760028 into etcd-io:master Sep 14, 2017
@lorneli lorneli deleted the bbolt_tx branch September 14, 2017 09:57
@gyuho gyuho changed the title tx: just close file once in WriteTo function tx.go: just close file once in WriteTo function Sep 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants