Defer close calls in save data reader functions
parent
1b5da99cda
commit
9a0d4a2698
|
@ -19,11 +19,15 @@ func readSystemSaveData(uuid []byte) (defs.SystemSaveData, error) {
|
||||||
return system, fmt.Errorf("failed to open save file: %s", err)
|
return system, fmt.Errorf("failed to open save file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
zstdDecoder, err := zstd.NewReader(file)
|
zstdDecoder, err := zstd.NewReader(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return system, fmt.Errorf("failed to create zstd decoder: %s", err)
|
return system, fmt.Errorf("failed to create zstd decoder: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer zstdDecoder.Close()
|
||||||
|
|
||||||
err = gob.NewDecoder(zstdDecoder).Decode(&system)
|
err = gob.NewDecoder(zstdDecoder).Decode(&system)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return system, fmt.Errorf("failed to deserialize save: %s", err)
|
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)
|
return session, fmt.Errorf("failed to open save file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
zstdDecoder, err := zstd.NewReader(file)
|
zstdDecoder, err := zstd.NewReader(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return session, fmt.Errorf("failed to create zstd decoder: %s", err)
|
return session, fmt.Errorf("failed to create zstd decoder: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer zstdDecoder.Close()
|
||||||
|
|
||||||
err = gob.NewDecoder(zstdDecoder).Decode(&session)
|
err = gob.NewDecoder(zstdDecoder).Decode(&session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return session, fmt.Errorf("failed to deserialize save: %s", err)
|
return session, fmt.Errorf("failed to deserialize save: %s", err)
|
||||||
|
|
Loading…
Reference in New Issue