Browse Source

Fix a memory leak in the test suite

This test creates a cycle between two `Func` objects (and indirectly
through their instance) which prevents anything from being collected.
This was found when running tests locally with address sanitizer, and
using a `Weak<T>` breaks the cycle to allow collecting resources.
pull/1593/head
Alex Crichton 5 years ago
parent
commit
6822c9bdc1
  1. 4
      tests/all/import_calling_export.rs

4
tests/all/import_calling_export.rs

@ -20,13 +20,15 @@ fn test_import_calling_export() {
let module = Module::new(&store, WAT).expect("failed to create module"); let module = Module::new(&store, WAT).expect("failed to create module");
let other = Rc::new(RefCell::new(None::<Func>)); let other = Rc::new(RefCell::new(None::<Func>));
let other2 = other.clone(); let other2 = Rc::downgrade(&other);
let callback_func = Func::new( let callback_func = Func::new(
&store, &store,
FuncType::new(Box::new([]), Box::new([])), FuncType::new(Box::new([]), Box::new([])),
move |_, _, _| { move |_, _, _| {
other2 other2
.upgrade()
.unwrap()
.borrow() .borrow()
.as_ref() .as_ref()
.expect("expected a function ref") .expect("expected a function ref")

Loading…
Cancel
Save