@@ -221,7 +221,7 @@ WasmBase::WasmBase(const std::shared_ptr<WasmHandleBase> &base_wasm_handle,
221221 started_from_(base_wasm_handle->wasm ()->wasm_vm()->cloneable()),
222222 envs_(base_wasm_handle->wasm ()->envs()),
223223 allowed_capabilities_(base_wasm_handle->wasm ()->allowed_capabilities_),
224- base_wasm_handle_ (base_wasm_handle) {
224+ base_wasm_handle_weak_ (base_wasm_handle) {
225225 if (started_from_ != Cloneable::NotCloneable) {
226226 wasm_vm_ = base_wasm_handle->wasm ()->wasm_vm ()->clone ();
227227 } else {
@@ -338,17 +338,27 @@ bool WasmBase::initialize() {
338338 }
339339
340340 if (started_from_ == Cloneable::NotCloneable) {
341- auto ok = wasm_vm_->load (base_wasm_handle_->wasm ()->moduleBytecode (),
342- base_wasm_handle_->wasm ()->modulePrecompiled (),
343- base_wasm_handle_->wasm ()->functionNames ());
341+ auto base_wasm_handle = base_wasm_handle_weak_.lock ();
342+ if (!base_wasm_handle) {
343+ fail (FailState::UnableToInitializeCode, " Base wasm handle is null" );
344+ return false ;
345+ }
346+ auto ok = wasm_vm_->load (base_wasm_handle->wasm ()->moduleBytecode (),
347+ base_wasm_handle->wasm ()->modulePrecompiled (),
348+ base_wasm_handle->wasm ()->functionNames ());
344349 if (!ok) {
345350 fail (FailState::UnableToInitializeCode, " Failed to load Wasm module from base Wasm" );
346351 return false ;
347352 }
348353 }
349354
350355 if (started_from_.has_value ()) {
351- abi_version_ = base_wasm_handle_->wasm ()->abiVersion ();
356+ auto base_wasm_handle = base_wasm_handle_weak_.lock ();
357+ if (!base_wasm_handle) {
358+ fail (FailState::UnableToInitializeCode, " Base wasm handle is null" );
359+ return false ;
360+ }
361+ abi_version_ = base_wasm_handle->wasm ()->abiVersion ();
352362 }
353363
354364 if (started_from_ != Cloneable::InstantiatedModule) {
0 commit comments