From 1a956374398f53337c9057a255681e2b24b03fa3 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Mon, 17 Oct 2022 12:49:49 -0700 Subject: [PATCH] Close files properly when returning an error (Arsen6331/itd#29) --- resources.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources.go b/resources.go index 4eb7307..4f753cf 100644 --- a/resources.go +++ b/resources.go @@ -70,6 +70,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er if err != nil { return nil, err } + defer m.Close() var manifest ResourceManifest err = json.NewDecoder(m).Decode(&manifest) @@ -77,6 +78,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er return nil, err } + m.Close() + log.Debug().Msg("Decoded manifest file") go func() { @@ -124,6 +127,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er Total: srcFi.Size(), Err: err, } + src.Close() return } @@ -138,6 +142,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er Total: srcFi.Size(), Err: err, } + src.Close() return } @@ -155,6 +160,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er Total: srcFi.Size(), Err: err, } + src.Close() return } @@ -189,6 +195,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er Sent: n, Err: err, } + src.Close() + dst.Close() return }