Fix block_pool_resource allocation and deallocation

This commit is contained in:
mutouyun 2024-01-06 18:17:57 +08:00
parent de80de3828
commit 01bbcf7dca

View File

@ -107,16 +107,20 @@ public:
}
auto &map = get_block_pool_map();
auto it = map.find(r_size);
if ((it == map.end()) || (it->second == nullptr)) LIBIMP_TRY {
if ((it == map.end()) || (it->second == nullptr)) {
block_pool_resource<0, 0> *bp = nullptr;
LIBIMP_TRY {
// If the corresponding memory resource cannot be found,
// create a temporary general-purpose block pool to deallocate memory.
it = map.emplace(r_size, new block_pool_resource<0, 0>).first;
it = map.emplace(r_size, bp = new block_pool_resource<0, 0>).first;
} LIBIMP_CATCH(...) {
// If the memory resource cannot be created,
// store the pointer directly to avoid leakage.
delete bp;
base_t::deallocate(p);
return;
}
}
it->second->deallocate(p);
}
};