Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/support/allocators/mt_pooled_secure.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ struct mt_pooled_secure_allocator : public std::allocator<T> {
using value_type = typename traits::value_type;
mt_pooled_secure_allocator(size_type nrequested_size = 32,
size_type nnext_size = 32,
size_type nmax_size = 0) noexcept
size_type nmax_size = 0,
size_type pools_count = std::thread::hardware_concurrency()) noexcept
{
// we add enough bytes to the requested size so that we can store the bucket as well
nrequested_size += sizeof(size_t);

size_t pools_count = std::thread::hardware_concurrency();
if (pools_count == 0) {
pools_count = 1;
}
pools.resize(pools_count);
for (size_t i = 0; i < pools_count; i++) {
pools[i] = std::make_unique<internal_pool>(nrequested_size, nnext_size, nmax_size);
Expand Down
15 changes: 15 additions & 0 deletions src/test/allocator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <support/allocators/mt_pooled_secure.h>
#include <support/lockedpool.h>

#include <limits>
Expand Down Expand Up @@ -234,4 +235,18 @@ BOOST_AUTO_TEST_CASE(lockedpool_tests_live)
BOOST_CHECK(pool.stats().used == initial.used);
}

BOOST_AUTO_TEST_CASE(mt_pooled_secure_allocator_zero_pool_count)
{
mt_pooled_secure_allocator<unsigned char> allocator{/*nrequested_size=*/32,
/*nnext_size=*/32,
/*nmax_size=*/0,
/*pools_count=*/0};

auto* p = allocator.allocate(1);
BOOST_REQUIRE(p != nullptr);
*p = 0x42;
BOOST_CHECK_EQUAL(*p, 0x42);
allocator.deallocate(p, 1);
}

BOOST_AUTO_TEST_SUITE_END()
Loading