Skip to content

Commit 08aef9c

Browse files
committed
convert base handle to weak ptr in wasm recover
1 parent db24a6a commit 08aef9c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/wasm.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,14 @@ void setWasmRecoverCallback(const std::string &vm_key,
606606
const std::shared_ptr<WasmHandleBase> &base_handle,
607607
const WasmHandleCloneFactory &clone_factory) {
608608
std::weak_ptr<WasmHandleBase> wasm_handle_for_copy = wasm_handle;
609-
wasm_handle->setRecoverVmCallback([vm_key, wasm_handle_for_copy, base_handle,
609+
std::weak_ptr<WasmHandleBase> base_handle_for_copy = base_handle;
610+
wasm_handle->setRecoverVmCallback([vm_key, wasm_handle_for_copy, base_handle_for_copy,
610611
clone_factory]() -> std::shared_ptr<WasmHandleBase> {
612+
const auto base_handle = base_handle_for_copy.lock();
613+
if (!base_handle) {
614+
std::cerr << "Failed to get base_handle shared_ptr in setRecoverVmCallback" << std::endl;
615+
return nullptr;
616+
}
611617
const auto &integration = base_handle->wasm()->wasm_vm()->integration();
612618
integration->trace("Start recover wasm_handle");
613619
auto it = local_wasms.find(vm_key);
@@ -694,9 +700,17 @@ void setPluginRecoverCallback(const std::string &key,
694700
const std::shared_ptr<WasmHandleBase> &base_handle,
695701
const std::shared_ptr<PluginBase> &plugin,
696702
const PluginHandleFactory &plugin_factory) {
703+
std::weak_ptr<WasmHandleBase> base_handle_for_copy = base_handle;
704+
697705
plugin_handle->setRecoverPluginCallback(
698-
[key, base_handle, plugin, plugin_factory](
706+
[key, base_handle_for_copy, plugin, plugin_factory](
699707
std::shared_ptr<WasmHandleBase> &wasm_handle) -> std::shared_ptr<PluginHandleBase> {
708+
const auto base_handle = base_handle_for_copy.lock();
709+
if (!base_handle) {
710+
std::cerr << "Failed to get base_handle shared_ptr in setRecoverPluginCallback"
711+
<< std::endl;
712+
return nullptr;
713+
}
700714
const auto &integration = base_handle->wasm()->wasm_vm()->integration();
701715
integration->trace("Start recover plugin_handle");
702716
auto it = local_plugins.find(key);

0 commit comments

Comments
 (0)