From 4fa658e687e5fed57ba4f3dba7562470878f9da5 Mon Sep 17 00:00:00 2001 From: Hoa Nguyen Date: Tue, 11 Jun 2024 16:02:36 +0700 Subject: [PATCH] refactor(store): add miss defer (#20602) --- store/v2/commitment/store.go | 3 +++ store/v2/migration/manager.go | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/store/v2/commitment/store.go b/store/v2/commitment/store.go index b67a1149c3..4a93dc823d 100644 --- a/store/v2/commitment/store.go +++ b/store/v2/commitment/store.go @@ -134,6 +134,7 @@ func (c *CommitStore) LoadVersion(targetVersion uint64) error { } if targetVersion < latestVersion { batch := c.db.NewBatch() + defer batch.Close() for version := latestVersion; version > targetVersion; version-- { cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) if err := batch.Delete(cInfoKey); err != nil { @@ -186,6 +187,7 @@ func (c *CommitStore) flushCommitInfo(version uint64, cInfo *proof.CommitInfo) e } batch := c.db.NewBatch() + defer batch.Close() cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, version)) value, err := cInfo.Marshal() if err != nil { @@ -306,6 +308,7 @@ func (c *CommitStore) Get(storeKey []byte, version uint64, key []byte) ([]byte, func (c *CommitStore) Prune(version uint64) (ferr error) { // prune the metadata batch := c.db.NewBatch() + defer batch.Close() for v := version; v > 0; v-- { cInfoKey := []byte(fmt.Sprintf(commitInfoKeyFmt, v)) if exist, _ := c.db.Has(cInfoKey); !exist { diff --git a/store/v2/migration/manager.go b/store/v2/migration/manager.go index 3dc3ef80e5..bd636dc3c6 100644 --- a/store/v2/migration/manager.go +++ b/store/v2/migration/manager.go @@ -197,7 +197,6 @@ func (m *Manager) writeChangeset() error { if err != nil { return err } - batch.Close() } return nil