From 74ef510288c3bbdf0a044a66e761b2270f514234 Mon Sep 17 00:00:00 2001 From: sowle Date: Sat, 9 Nov 2024 19:46:51 +0100 Subject: [PATCH] wallets_manager: wallet callback lifetime management fixed --- src/wallet/wallets_manager.cpp | 4 +++- src/wallet/wallets_manager.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 426aff27..8859ec8d 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1051,7 +1051,8 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st w->set_use_deffered_global_outputs(m_use_deffered_global_outputs); owr.wallet_id = m_wallet_id_counter++; - w->callback(std::shared_ptr(new i_wallet_to_i_backend_adapter(this, owr.wallet_id))); + std::shared_ptr w_cb{new i_wallet_to_i_backend_adapter(this, owr.wallet_id)}; + w->callback(w_cb); if (m_remote_node_mode) { w->set_core_proxy(m_rpc_proxy); @@ -1112,6 +1113,7 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st EXCLUSIVE_CRITICAL_REGION_LOCAL(m_wallets_lock); wallet_vs_options& wo = m_wallets[owr.wallet_id]; **wo.w = w; + wo.w_cb = w_cb; owr.wallet_file_size = w->get_wallet_file_size(); get_wallet_info(wo, owr.wi); init_wallet_entry(wo, owr.wallet_id); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 76a8191e..4e7f73a0 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -55,6 +55,7 @@ public: { currency::core_runtime_config core_conf; epee::locked_object, wallet_lock_time_watching_policy> w; + std::shared_ptr w_cb; // not using locked_object here, cuz w_cb is accessed only via it's wallet -- sowle typedef epee::locked_object, wallet_lock_time_watching_policy>::lock_shared_ptr wallet_lock_object; std::shared_ptr rpc_wrapper; //500 bytes of extra data, we can afford it, to have rpc-like invoke map std::atomic do_mining;