diff --git a/src/support/allocators/secure.h b/src/support/allocators/secure.h index b2076bea07b..558f835f116 100644 --- a/src/support/allocators/secure.h +++ b/src/support/allocators/secure.h @@ -17,27 +17,14 @@ // out of memory and clears its contents before deletion. // template -struct secure_allocator : public std::allocator { - using base = std::allocator; - using traits = std::allocator_traits; - using size_type = typename traits::size_type; - using difference_type = typename traits::difference_type; - using pointer = typename traits::pointer; - using const_pointer = typename traits::const_pointer; - using value_type = typename traits::value_type; - secure_allocator() noexcept {} - secure_allocator(const secure_allocator& a) noexcept : base(a) {} +struct secure_allocator { + using value_type = T; + + secure_allocator() = default; template - secure_allocator(const secure_allocator& a) noexcept : base(a) - { - } - ~secure_allocator() noexcept {} - template - struct rebind { - typedef secure_allocator other; - }; + secure_allocator(const secure_allocator&) noexcept {} - T* allocate(std::size_t n, const void* hint = nullptr) + T* allocate(std::size_t n) { T* allocation = static_cast(LockedPoolManager::Instance().alloc(sizeof(T) * n)); if (!allocation) { @@ -53,6 +40,17 @@ struct secure_allocator : public std::allocator { } LockedPoolManager::Instance().free(p); } + + template + friend bool operator==(const secure_allocator&, const secure_allocator&) noexcept + { + return true; + } + template + friend bool operator!=(const secure_allocator&, const secure_allocator&) noexcept + { + return false; + } }; // This is exactly like std::string, but with a custom allocator. diff --git a/src/support/allocators/zeroafterfree.h b/src/support/allocators/zeroafterfree.h index 2dc644c242a..6d50eb70a6f 100644 --- a/src/support/allocators/zeroafterfree.h +++ b/src/support/allocators/zeroafterfree.h @@ -12,31 +12,36 @@ #include template -struct zero_after_free_allocator : public std::allocator { - using base = std::allocator; - using traits = std::allocator_traits; - using size_type = typename traits::size_type; - using difference_type = typename traits::difference_type; - using pointer = typename traits::pointer; - using const_pointer = typename traits::const_pointer; - using value_type = typename traits::value_type; - zero_after_free_allocator() noexcept {} - zero_after_free_allocator(const zero_after_free_allocator& a) noexcept : base(a) {} +struct zero_after_free_allocator { + using value_type = T; + + zero_after_free_allocator() noexcept = default; template - zero_after_free_allocator(const zero_after_free_allocator& a) noexcept : base(a) + zero_after_free_allocator(const zero_after_free_allocator&) noexcept + { + } + + T* allocate(std::size_t n) { + return std::allocator{}.allocate(n); } - ~zero_after_free_allocator() noexcept {} - template - struct rebind { - typedef zero_after_free_allocator other; - }; void deallocate(T* p, std::size_t n) { if (p != nullptr) memory_cleanse(p, sizeof(T) * n); - std::allocator::deallocate(p, n); + std::allocator{}.deallocate(p, n); + } + + template + friend bool operator==(const zero_after_free_allocator&, const zero_after_free_allocator&) noexcept + { + return true; + } + template + friend bool operator!=(const zero_after_free_allocator&, const zero_after_free_allocator&) noexcept + { + return false; } };