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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user