Clone import in instantiate to prevent import move

This commit is contained in:
Brandon Fish
2019-02-20 09:52:42 -06:00
parent d2f3023191
commit b073145dbb
2 changed files with 2 additions and 3 deletions

View File

@ -467,7 +467,7 @@ pub unsafe extern "C" fn wasmer_instantiate(
wasmer_import_export_kind::WASM_GLOBAL => import.value.global as *mut Export, wasmer_import_export_kind::WASM_GLOBAL => import.value.global as *mut Export,
wasmer_import_export_kind::WASM_TABLE => import.value.table as *mut Export, wasmer_import_export_kind::WASM_TABLE => import.value.table as *mut Export,
}; };
namespace.insert(import_name, unsafe { *Box::from_raw(export) }); // TODO Review namespace.insert(import_name, unsafe { (&*export).clone() });
} }
for (module_name, namespace) in namespaces.into_iter() { for (module_name, namespace) in namespaces.into_iter() {
import_object.register(module_name, namespace); import_object.register(module_name, namespace);
@ -488,7 +488,6 @@ pub unsafe extern "C" fn wasmer_instantiate(
} }
}; };
unsafe { *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t }; unsafe { *instance = Box::into_raw(Box::new(new_instance)) as *mut wasmer_instance_t };
Box::into_raw(Box::new(import_object));
wasmer_result_t::WASMER_OK wasmer_result_t::WASMER_OK
} }

View File

@ -84,7 +84,7 @@ int main()
assert(0 == strcmp(actual_str, "Hello, World!")); assert(0 == strcmp(actual_str, "Hello, World!"));
printf("Destroying func\n"); printf("Destroying func\n");
// wasmer_func_destroy(func); wasmer_func_destroy(func);
printf("Destroy instance\n"); printf("Destroy instance\n");
wasmer_instance_destroy(instance); wasmer_instance_destroy(instance);
return 0; return 0;