From 70121091d6c34d17f9b66b6d8a7e35c74eb4cd78 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Tue, 6 May 2025 17:59:03 +0800 Subject: [PATCH] Fix the issue caused by inconsistent lifecycle of the global IPC object. --- src/libipc/ipc.cpp | 12 ++++++------ test/imp/test_imp_system.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libipc/ipc.cpp b/src/libipc/ipc.cpp index 4316e36..5108648 100755 --- a/src/libipc/ipc.cpp +++ b/src/libipc/ipc.cpp @@ -76,18 +76,18 @@ ipc::buff_t make_cache(T &data, std::size_t size) { } acc_t *cc_acc(std::string const &pref) { - static ipc::unordered_map handles; + static auto *phs = new ipc::unordered_map; // no delete static std::mutex lock; std::lock_guard guard {lock}; - auto it = handles.find(pref); - if (it == handles.end()) { + auto it = phs->find(pref); + if (it == phs->end()) { std::string shm_name {ipc::make_prefix(pref, "CA_CONN__")}; ipc::shm::handle h; if (!h.acquire(shm_name.c_str(), sizeof(acc_t))) { ipc::error("[cc_acc] acquire failed: %s\n", shm_name.c_str()); return nullptr; } - it = handles.emplace(pref, std::move(h)).first; + it = phs->emplace(pref, std::move(h)).first; } return static_cast(it->second.get()); } @@ -248,8 +248,8 @@ auto& chunk_storages() { }; using deleter_t = void (*)(chunk_handle_t*); using chunk_handle_ptr_t = std::unique_ptr; - static ipc::map chunk_hs; - return chunk_hs; + static auto *chunk_hs = new ipc::map; // no delete + return *chunk_hs; } chunk_info_t *chunk_storage_info(conn_info_head *inf, std::size_t chunk_size) { diff --git a/test/imp/test_imp_system.cpp b/test/imp/test_imp_system.cpp index 802ebd4..90d57bd 100644 --- a/test/imp/test_imp_system.cpp +++ b/test/imp/test_imp_system.cpp @@ -6,5 +6,5 @@ TEST(system, conf) { auto ret = ipc::sys::conf(ipc::sys::info::page_size); EXPECT_TRUE(ret); - EXPECT_EQ(ret.value(), 4096); + EXPECT_GE(ret.value(), 4096); }