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.
This commit is contained in:
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user