diff options
author | Kenneth Heafield <github@kheafield.com> | 2021-12-09 14:05:43 +0300 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2021-12-09 14:05:43 +0300 |
commit | 4ae14f726fbc37d74cf0841e496901c3f494fff3 (patch) | |
tree | 941cd66b28519ae283fd18206faa09893e1bad98 | |
parent | a5f86a37cd4cf98b5f857a23c90805214602a2eb (diff) |
Enforce minimum size in FreePoolrelative-headers
-rw-r--r-- | util/pool.hh | 7 |
1 files 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<void**>(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 |