Use std::unique_ptr<> instead of raw session pointers

Simplify connection_pool_base_impl by using std::unique_ptr<> which
ensures that the pointers are deleted, without having to do it
explicitly.
This commit is contained in:
Vadim Zeitlin
2025-09-20 16:29:02 +02:00
parent e1b841f5bd
commit 5b3da80db4

View File

@@ -29,17 +29,11 @@ struct connection_pool_base_impl
sessions_.resize(size);
for (std::size_t i = 0; i != size; ++i)
{
sessions_[i] = std::make_pair(true, new session());
sessions_[i] = std::make_pair(true, std::make_unique<session>());
}
}
~connection_pool_base_impl()
{
for (std::size_t i = 0; i != sessions_.size(); ++i)
{
delete sessions_[i].second;
}
}
~connection_pool_base_impl() = default;
bool find_free(std::size_t & pos)
{
@@ -57,7 +51,7 @@ struct connection_pool_base_impl
// by convention, first == true means the entry is free (not used)
std::vector<std::pair<bool, session *> > sessions_;
std::vector<std::pair<bool, std::unique_ptr<session>> > sessions_;
};
} // anonymous namespace