From 6822c9bdc18e543be540b4b656602ff5cd6b875c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 24 Apr 2020 13:34:51 -0700 Subject: [PATCH] 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` breaks the cycle to allow collecting resources. --- tests/all/import_calling_export.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/all/import_calling_export.rs b/tests/all/import_calling_export.rs index 97c95384d0..7affdd8759 100644 --- a/tests/all/import_calling_export.rs +++ b/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 other = Rc::new(RefCell::new(None::)); - let other2 = other.clone(); + let other2 = Rc::downgrade(&other); let callback_func = Func::new( &store, FuncType::new(Box::new([]), Box::new([])), move |_, _, _| { other2 + .upgrade() + .unwrap() .borrow() .as_ref() .expect("expected a function ref")