Skip to content

Commit

Permalink
fix deepsource: Unsafe defer of os.Close (#1836)
Browse files Browse the repository at this point in the history
* fix deepsource: Unsafe defer of os.Close

* apply suggestion

Co-authored-by: Yusuke Kato <[email protected]>
  • Loading branch information
datelier and kpango authored Nov 18, 2022
1 parent 9f0f69f commit 8e7980a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions hack/benchmark/src/singleflight/singleflight_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"
"time"

"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/singleflight"
stdsingleflight "golang.org/x/sync/singleflight"
)
Expand Down Expand Up @@ -261,12 +262,18 @@ func Benchmark_group_Do_with_vald_internal_singleflight(b *testing.B) {
}
}

func toCSV(name string, r []Result) error {
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fs.ModePerm)
func toCSV(name string, r []Result) (err error) {
var f *os.File
f, err = os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fs.ModePerm)
if err != nil {
return err
}
defer f.Close()
defer func() {
e := f.Close()
if e != nil {
err = errors.Wrap(err, e.Error())
}
}()
_, err = fmt.Fprintln(f, "goroutine,duration,hit_rate")
if err != nil {
return err
Expand Down

0 comments on commit 8e7980a

Please sign in to comment.