From ace0f055074a6ecee0f9893d545f0ff6f7fc3c45 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 11 Jan 2023 14:22:28 +0100 Subject: properly close files in edge cases in various places --- util/lamport/persisted_clock.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'util/lamport') diff --git a/util/lamport/persisted_clock.go b/util/lamport/persisted_clock.go index b9246f73..a069b379 100644 --- a/util/lamport/persisted_clock.go +++ b/util/lamport/persisted_clock.go @@ -3,7 +3,7 @@ package lamport import ( "errors" "fmt" - "io/ioutil" + "io" "os" "github.com/go-git/go-billy/v5" @@ -77,9 +77,14 @@ func (pc *PersistedClock) read() error { if err != nil { return err } - defer f.Close() - content, err := ioutil.ReadAll(f) + content, err := io.ReadAll(f) + if err != nil { + _ = f.Close() + return err + } + + err = f.Close() if err != nil { return err } -- cgit