diff --git a/api/savedata-helper.go b/api/savedata-helper.go index e96afbe..0b8f65e 100644 --- a/api/savedata-helper.go +++ b/api/savedata-helper.go @@ -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)