Skip to content

Commit

Permalink
fix: memory leak in Import (backport #773) (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang authored May 19, 2023
1 parent e1e212a commit 94ab9b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- [#726](https://github.com/cosmos/iavl/pull/726) Make `KVPair` and `ChangeSet` serializable with protobuf.

### Bug Fixes

- [#773](https://github.com/cosmos/iavl/pull/773) Fix memory leak in `Import`.

## 0.19.5 (February 2, 2023)

### Breaking Changes
Expand Down
26 changes: 10 additions & 16 deletions import.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,18 @@ func (i *Importer) Add(exportNode *ExportNode) error {
// importer in an inconsistent state when we return an error.
stackSize := len(i.stack)
switch {
case node.height == 0:
node.size = 1
case stackSize >= 2 && i.stack[stackSize-1].height < node.height && i.stack[stackSize-2].height < node.height:
node.leftNode = i.stack[stackSize-2]
node.leftHash = node.leftNode.hash
node.rightNode = i.stack[stackSize-1]
node.rightHash = node.rightNode.hash
leftNode := i.stack[stackSize-2]
rightNode := i.stack[stackSize-1]
node.leftHash = leftNode.hash
node.rightHash = rightNode.hash
node.size = leftNode.size + rightNode.size
case stackSize >= 1 && i.stack[stackSize-1].height < node.height:
node.leftNode = i.stack[stackSize-1]
node.leftHash = node.leftNode.hash
}

if node.height == 0 {
node.size = 1
}
if node.leftNode != nil {
node.size += node.leftNode.size
}
if node.rightNode != nil {
node.size += node.rightNode.size
leftNode := i.stack[stackSize-1]
node.leftHash = leftNode.hash
node.size = leftNode.size
}

_, err := node._hash()
Expand Down

0 comments on commit 94ab9b2

Please sign in to comment.