diff options
author | Michael Muré <batolettre@gmail.com> | 2023-01-11 14:22:28 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2023-01-11 14:22:58 +0100 |
commit | ace0f055074a6ecee0f9893d545f0ff6f7fc3c45 (patch) | |
tree | 1c6732eb1a87ee9f65da62a6cf156bd441a2f02a /cache/subcache.go | |
parent | 2664332bfd17094dd8a485ea085099d6eac33068 (diff) | |
download | git-bug-ace0f055074a6ecee0f9893d545f0ff6f7fc3c45.tar.gz |
properly close files in edge cases in various places
Diffstat (limited to 'cache/subcache.go')
-rw-r--r-- | cache/subcache.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/cache/subcache.go b/cache/subcache.go index 6a9559ef..7b599b10 100644 --- a/cache/subcache.go +++ b/cache/subcache.go @@ -101,15 +101,20 @@ func (sc *SubCache[EntityT, ExcerptT, CacheT]) Load() error { return err } - decoder := gob.NewDecoder(f) - aux := struct { Version uint Excerpts map[entity.Id]ExcerptT }{} + decoder := gob.NewDecoder(f) err = decoder.Decode(&aux) if err != nil { + _ = f.Close() + return err + } + + err = f.Close() + if err != nil { return err } @@ -173,6 +178,7 @@ func (sc *SubCache[EntityT, ExcerptT, CacheT]) write() error { _, err = f.Write(data.Bytes()) if err != nil { + _ = f.Close() return err } |