Skip to content

Commit

Permalink
Problem: memory leak during memiavl import (#1036)
Browse files Browse the repository at this point in the history
* Problem: memory leak during memiavl import

Solution:
- break up the unnesserary references

* Update CHANGELOG.md

Signed-off-by: yihuang <huang@crypto.com>

* Update memiavl/import.go

Co-authored-by: mmsqe <mavis@crypto.com>
Signed-off-by: yihuang <huang@crypto.com>

---------

Signed-off-by: yihuang <huang@crypto.com>
Co-authored-by: mmsqe <mavis@crypto.com>
  • Loading branch information
yihuang and mmsqe authored May 24, 2023
1 parent de7e559 commit 81e9eea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

- [#833](/~https://github.com/crypto-org-chain/cronos/pull/833) Fix rollback command.
- [#945](/~https://github.com/crypto-org-chain/cronos/pull/945) Fix no handler exists for proposal type error when update-client due to wrong ibc route.
- [#1036](/~https://github.com/crypto-org-chain/cronos/pull/1036) Fix memiavl import memory leak.

### Improvements

Expand Down
5 changes: 5 additions & 0 deletions memiavl/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ func (i *importer) Add(n *iavl.ExportNode) error {
right: rightNode,
}
nodeHash := node.Hash()

// remove unnecessary reference to avoid memory leak
node.left = nil
node.right = nil

preTrees := uint8(len(i.nodeStack) - 2)
if err := i.writeBranch(node.version, uint32(node.size), node.height, preTrees, keyLeaf, nodeHash); err != nil {
return err
Expand Down

0 comments on commit 81e9eea

Please sign in to comment.