Skip to content

Commit

Permalink
Clone import in instantiate to prevent import move
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Feb 20, 2019
1 parent d2f3023 commit b073145
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/runtime-c-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_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() {
import_object.register(module_name, namespace);
Expand All @@ -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 };
Box::into_raw(Box::new(import_object));
wasmer_result_t::WASMER_OK
}

Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/tests/test-import-function.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int main()
assert(0 == strcmp(actual_str, "Hello, World!"));

printf("Destroying func\n");
// wasmer_func_destroy(func);
wasmer_func_destroy(func);
printf("Destroy instance\n");
wasmer_instance_destroy(instance);
return 0;
Expand Down

0 comments on commit b073145

Please sign in to comment.