Fix a possible use-after-free with Global (#956)

* Fix a possible use-after-free with `Global`

This commit fixes an issue with the implementation of the
`wasmtime::Global` type where if it previously outlived the original
`Instance` it came from then you could run into a use-after-free. Now
the `Global` type holds onto its underlying `InstanceHandle` to ensure
it retains ownership of the underlying backing store of the global's
memory.

* rustfmt
This commit is contained in:
Alex Crichton
2020-02-19 20:57:41 -06:00
committed by GitHub
parent b69a061d23
commit 4283fdc862
4 changed files with 133 additions and 63 deletions

View File

@@ -16,8 +16,6 @@ use std::any::Any;
use std::rc::Rc;
use wasmtime_runtime::VMFunctionBody;
pub use self::global::GlobalState;
pub fn generate_func_export(
ft: &FuncType,
func: &Rc<dyn Callable + 'static>,
@@ -46,8 +44,10 @@ pub fn generate_global_export(
store: &Store,
gt: &GlobalType,
val: Val,
) -> Result<(wasmtime_runtime::Export, GlobalState)> {
create_global(store, gt, val)
) -> Result<(wasmtime_runtime::InstanceHandle, wasmtime_runtime::Export)> {
let instance = create_global(store, gt, val)?;
let export = instance.lookup("global").expect("global export");
Ok((instance, export))
}
pub fn generate_memory_export(