Fix memory leak in runtime interface (#4837)

* Fix memory leak in runtime interface

We used `slice::from_raw_parts` in runtime-interface which did not free
the memory afterwards. This pr changes it to `Vec::from_raw_parts` to
make sure `drop` is called properly and the values are freed.

* Check that `len` is non-zero

* Adds comment
This commit is contained in:
Bastian Köcher
2020-02-06 14:26:41 +01:00
committed by GitHub
parent 3c79e6d03c
commit c7867e5125
4 changed files with 68 additions and 12 deletions
@@ -113,3 +113,18 @@ fn test_overwrite_native_function_implementation() {
fn test_u128_i128_as_parameter_and_return_value() {
call_wasm_method::<HostFunctions>("test_u128_i128_as_parameter_and_return_value");
}
#[test]
fn test_vec_return_value_memory_is_freed() {
call_wasm_method::<HostFunctions>("test_vec_return_value_memory_is_freed");
}
#[test]
fn test_encoded_return_value_memory_is_freed() {
call_wasm_method::<HostFunctions>("test_encoded_return_value_memory_is_freed");
}
#[test]
fn test_array_return_value_memory_is_freed() {
call_wasm_method::<HostFunctions>("test_array_return_value_memory_is_freed");
}