From e6616cd225e62ea2b7befbe5885427926bb36953 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 12 May 2020 21:11:54 +0200 Subject: [PATCH] Added error on opening same wallet file --- contrib/epee/include/syncobj.h | 3 ++- src/wallet/wallets_manager.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/contrib/epee/include/syncobj.h b/contrib/epee/include/syncobj.h index 457c5f37..3494194a 100644 --- a/contrib/epee/include/syncobj.h +++ b/contrib/epee/include/syncobj.h @@ -705,7 +705,8 @@ namespace epee #define EXCLUSIVE_CRITICAL_REGION_LOCAL(x) boost::unique_lock< boost::shared_mutex > critical_region_var(x) #define SHARED_CRITICAL_REGION_BEGIN(x) { SHARED_CRITICAL_REGION_LOCAL(x) +#define SHARED_CRITICAL_REGION_END() } #define EXCLUSIVE_CRITICAL_REGION_BEGIN(x) { EXCLUSIVE_CRITICAL_REGION_LOCAL(x) - +#define EXCLUSIVE_CRITICAL_REGION_END() } } diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 627ecabe..6bd89cde 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -732,6 +732,16 @@ std::string wallets_manager::get_my_offers(const bc_services::core_offers_filter std::string wallets_manager::open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr) { + // check if that file already opened + SHARED_CRITICAL_REGION_BEGIN(m_wallets_lock); + for (auto& wallet_entry : m_wallets) + { + if (wallet_entry.second.w.unlocked_get()->get_wallet_path() == path) + return API_RETURN_CODE_ALREADY_EXISTS; + } + SHARED_CRITICAL_REGION_END(); + + std::shared_ptr w(new tools::wallet2()); owr.wallet_id = m_wallet_id_counter++; @@ -784,6 +794,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; get_wallet_info(wo, owr.wi);