From 4fa17a3fb10ca093143baff42cabfd30492a88cf Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Mon, 3 Jun 2024 13:53:40 +0800 Subject: [PATCH] [patchstore] fix close files (#4268) Signed-off-by: guoguangwu Co-authored-by: dustinxie --- action/protocol/staking/patchstore.go | 1 + state/factory/patchstore.go | 1 + 2 files changed, 2 insertions(+) diff --git a/action/protocol/staking/patchstore.go b/action/protocol/staking/patchstore.go index b807b28a43..96c07385fb 100644 --- a/action/protocol/staking/patchstore.go +++ b/action/protocol/staking/patchstore.go @@ -60,6 +60,7 @@ func (store *PatchStore) Read(height uint64) (CandidateList, CandidateList, Cand if err != nil { return nil, nil, nil, err } + defer file.Close() reader := csv.NewReader(file) reader.FieldsPerRecord = -1 listByName, err := store.read(reader) diff --git a/state/factory/patchstore.go b/state/factory/patchstore.go index 2cb30a9582..597ebb682d 100644 --- a/state/factory/patchstore.go +++ b/state/factory/patchstore.go @@ -54,6 +54,7 @@ func newPatchStore(fpath string) (*patchStore, error) { if err != nil { return nil, errors.Wrapf(err, "failed to open kvstore patch, %s", fpath) } + defer file.Close() reader := csv.NewReader(file) reader.FieldsPerRecord = -1 for {