Skip to content

Commit

Permalink
Merge pull request #220 from CosmWasm/create-patch-0.13.1
Browse files Browse the repository at this point in the history
Create patch 0.13.1 to fix memory leak
  • Loading branch information
webmaster128 authored May 26, 2021
2 parents 403b5f4 + 756d55d commit c68651b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 66 deletions.
102 changes: 38 additions & 64 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ default = []
backtraces = []

[dependencies]
cosmwasm-std = { version = "0.13.0", features = ["iterator"]}
cosmwasm-vm = { version = "0.13.0", features = ["iterator"] }
cosmwasm-std = { version = "0.13.2", features = ["iterator"]}
cosmwasm-vm = { version = "0.13.2", features = ["iterator"] }
errno = "0.2"
serde_json = "1.0"
thiserror = "1.0"
Expand Down
Binary file modified api/libwasmvm.dylib
Binary file not shown.
Binary file modified api/libwasmvm.so
Binary file not shown.
9 changes: 9 additions & 0 deletions src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl GoIter {
}
}

// In this block, we use Buffer::read() for both `key_buf` and `value_buf`
// in order to preserve the behaviour for optional values. Buffer::consume()
// does not return an Option. Since we `return` in none of the cases, we can
// cleanup afterwards. With CosmWasm 0.14 this code is completely refactored.
let okey = unsafe { key_buf.read() };
let result = match okey {
Some(key) => {
Expand All @@ -92,6 +96,11 @@ impl GoIter {
}
None => Ok(None),
};

// Clean up memory allocations created by us
let _key = unsafe { key_buf.consume() };
let _value = unsafe { value_buf.consume() };

(result, gas_info)
}
}

0 comments on commit c68651b

Please sign in to comment.