Keep frame info registered until internal instance is gone (#1514)

This commit fixes an issue where the global registration of frame data
goes away once the `wasmtime::Module` has been dropped. Even after this
has been dropped, though, there may still be `wasmtime::Func` instances
which reference the original module, so it's only once the underlying
`wasmtime_runtime::Instance` has gone away that we can drop everything.

Closes #1479
This commit is contained in:
Alex Crichton
2020-04-16 14:00:49 -05:00
committed by GitHub
parent 7da6101732
commit 99adc1d218
5 changed files with 38 additions and 34 deletions

View File

@@ -411,3 +411,25 @@ wasm backtrace:
);
Ok(())
}
#[test]
fn present_after_module_drop() -> Result<()> {
let store = Store::default();
let module = Module::new(&store, r#"(func (export "foo") unreachable)"#)?;
let instance = Instance::new(&module, &[])?;
let func = instance.exports()[0].func().unwrap().clone();
println!("asserting before we drop modules");
assert_trap(func.call(&[]).unwrap_err().downcast()?);
drop((instance, module));
println!("asserting after drop");
assert_trap(func.call(&[]).unwrap_err().downcast()?);
return Ok(());
fn assert_trap(t: Trap) {
println!("{}", t);
assert_eq!(t.trace().len(), 1);
assert_eq!(t.trace()[0].func_index(), 0);
}
}