From 4ae14f726fbc37d74cf0841e496901c3f494fff3 Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Thu, 9 Dec 2021 11:05:43 +0000 Subject: Enforce minimum size in FreePool --- util/pool.hh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/util/pool.hh b/util/pool.hh index d72400b..b3cd9e5 100644 --- a/util/pool.hh +++ b/util/pool.hh @@ -87,7 +87,9 @@ class Pool { class FreePool { public: explicit FreePool(std::size_t element_size) - : free_list_(NULL), element_size_(element_size) {} + : free_list_(NULL), + element_size_(element_size), + padded_size_(std::max(element_size_, sizeof(void*))) {} void *Allocate() { if (free_list_) { @@ -95,7 +97,7 @@ class FreePool { free_list_ = *reinterpret_cast(free_list_); return ret; } else { - return backing_.Allocate(element_size_); + return backing_.Allocate(padded_size_); } } @@ -112,6 +114,7 @@ class FreePool { Pool backing_; const std::size_t element_size_; + const std::size_t padded_size_; }; } // namespace util -- cgit v1.2.3