Skip to content

Commit 7012109

Browse files
committed
Fix the issue caused by inconsistent lifecycle of the global IPC object.
1 parent 32c2be2 commit 7012109

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/libipc/ipc.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ ipc::buff_t make_cache(T &data, std::size_t size) {
7676
}
7777

7878
acc_t *cc_acc(std::string const &pref) {
79-
static ipc::unordered_map<std::string, ipc::shm::handle> handles;
79+
static auto *phs = new ipc::unordered_map<std::string, ipc::shm::handle>; // no delete
8080
static std::mutex lock;
8181
std::lock_guard<std::mutex> guard {lock};
82-
auto it = handles.find(pref);
83-
if (it == handles.end()) {
82+
auto it = phs->find(pref);
83+
if (it == phs->end()) {
8484
std::string shm_name {ipc::make_prefix(pref, "CA_CONN__")};
8585
ipc::shm::handle h;
8686
if (!h.acquire(shm_name.c_str(), sizeof(acc_t))) {
8787
ipc::error("[cc_acc] acquire failed: %s\n", shm_name.c_str());
8888
return nullptr;
8989
}
90-
it = handles.emplace(pref, std::move(h)).first;
90+
it = phs->emplace(pref, std::move(h)).first;
9191
}
9292
return static_cast<acc_t *>(it->second.get());
9393
}
@@ -248,8 +248,8 @@ auto& chunk_storages() {
248248
};
249249
using deleter_t = void (*)(chunk_handle_t*);
250250
using chunk_handle_ptr_t = std::unique_ptr<chunk_handle_t, deleter_t>;
251-
static ipc::map<std::size_t, chunk_handle_ptr_t> chunk_hs;
252-
return chunk_hs;
251+
static auto *chunk_hs = new ipc::map<std::size_t, chunk_handle_ptr_t>; // no delete
252+
return *chunk_hs;
253253
}
254254

255255
chunk_info_t *chunk_storage_info(conn_info_head *inf, std::size_t chunk_size) {

test/imp/test_imp_system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
TEST(system, conf) {
77
auto ret = ipc::sys::conf(ipc::sys::info::page_size);
88
EXPECT_TRUE(ret);
9-
EXPECT_EQ(ret.value(), 4096);
9+
EXPECT_GE(ret.value(), 4096);
1010
}

0 commit comments

Comments
 (0)