Close files properly when returning an error (Arsen6331/itd#29)

This commit is contained in:
Elara 2022-10-17 12:49:49 -07:00
parent bb017b471e
commit a01f1b9d92

View File

@ -70,6 +70,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer m.Close()
var manifest ResourceManifest var manifest ResourceManifest
err = json.NewDecoder(m).Decode(&manifest) err = json.NewDecoder(m).Decode(&manifest)
@ -77,6 +78,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return nil, err return nil, err
} }
m.Close()
log.Debug().Msg("Decoded manifest file") log.Debug().Msg("Decoded manifest file")
go func() { go func() {
@ -124,6 +127,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Total: srcFi.Size(), Total: srcFi.Size(),
Err: err, Err: err,
} }
src.Close()
return return
} }
@ -138,6 +142,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Total: srcFi.Size(), Total: srcFi.Size(),
Err: err, Err: err,
} }
src.Close()
return return
} }
@ -155,6 +160,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Total: srcFi.Size(), Total: srcFi.Size(),
Err: err, Err: err,
} }
src.Close()
return return
} }
@ -189,6 +195,8 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
Sent: n, Sent: n,
Err: err, Err: err,
} }
src.Close()
dst.Close()
return return
} }