Defer close calls in save data reader functions

pull/4/head
maru 9 months ago
parent 1b5da99cda
commit 9a0d4a2698
No known key found for this signature in database
GPG Key ID: 37689350E9CD0F0D

@ -19,11 +19,15 @@ func readSystemSaveData(uuid []byte) (defs.SystemSaveData, error) {
return system, fmt.Errorf("failed to open save file: %s", err)
}
defer file.Close()
zstdDecoder, err := zstd.NewReader(file)
if err != nil {
return system, fmt.Errorf("failed to create zstd decoder: %s", err)
}
defer zstdDecoder.Close()
err = gob.NewDecoder(zstdDecoder).Decode(&system)
if err != nil {
return system, fmt.Errorf("failed to deserialize save: %s", err)
@ -45,11 +49,15 @@ func readSessionSaveData(uuid []byte, slotID int) (defs.SessionSaveData, error)
return session, fmt.Errorf("failed to open save file: %s", err)
}
defer file.Close()
zstdDecoder, err := zstd.NewReader(file)
if err != nil {
return session, fmt.Errorf("failed to create zstd decoder: %s", err)
}
defer zstdDecoder.Close()
err = gob.NewDecoder(zstdDecoder).Decode(&session)
if err != nil {
return session, fmt.Errorf("failed to deserialize save: %s", err)

Loading…
Cancel
Save