@@ -200,7 +200,7 @@ WasmBase::WasmBase(const std::shared_ptr<WasmHandleBase> &base_wasm_handle,
200
200
started_from_(base_wasm_handle->wasm ()->wasm_vm()->cloneable()),
201
201
envs_(base_wasm_handle->wasm ()->envs()),
202
202
allowed_capabilities_(base_wasm_handle->wasm ()->allowed_capabilities_),
203
- base_wasm_handle_ (base_wasm_handle) {
203
+ base_wasm_handle_weak_ (base_wasm_handle) {
204
204
if (started_from_ != Cloneable::NotCloneable) {
205
205
wasm_vm_ = base_wasm_handle->wasm ()->wasm_vm ()->clone ();
206
206
} else {
@@ -317,17 +317,27 @@ bool WasmBase::initialize() {
317
317
}
318
318
319
319
if (started_from_ == Cloneable::NotCloneable) {
320
- auto ok = wasm_vm_->load (base_wasm_handle_->wasm ()->moduleBytecode (),
321
- base_wasm_handle_->wasm ()->modulePrecompiled (),
322
- base_wasm_handle_->wasm ()->functionNames ());
320
+ auto base_wasm_handle = base_wasm_handle_weak_.lock ();
321
+ if (!base_wasm_handle) {
322
+ fail (FailState::UnableToInitializeCode, " Base wasm handle is null" );
323
+ return false ;
324
+ }
325
+ auto ok = wasm_vm_->load (base_wasm_handle->wasm ()->moduleBytecode (),
326
+ base_wasm_handle->wasm ()->modulePrecompiled (),
327
+ base_wasm_handle->wasm ()->functionNames ());
323
328
if (!ok) {
324
329
fail (FailState::UnableToInitializeCode, " Failed to load Wasm module from base Wasm" );
325
330
return false ;
326
331
}
327
332
}
328
333
329
334
if (started_from_.has_value ()) {
330
- abi_version_ = base_wasm_handle_->wasm ()->abiVersion ();
335
+ auto base_wasm_handle = base_wasm_handle_weak_.lock ();
336
+ if (!base_wasm_handle) {
337
+ fail (FailState::UnableToInitializeCode, " Base wasm handle is null" );
338
+ return false ;
339
+ }
340
+ abi_version_ = base_wasm_handle->wasm ()->abiVersion ();
331
341
}
332
342
333
343
if (started_from_ != Cloneable::InstantiatedModule) {
0 commit comments