diff options
Diffstat (limited to 'Swiften/Base/SafeAllocator.h')
-rw-r--r-- | Swiften/Base/SafeAllocator.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Swiften/Base/SafeAllocator.h b/Swiften/Base/SafeAllocator.h index 9f9dd42..8a8b25e 100644 --- a/Swiften/Base/SafeAllocator.h +++ b/Swiften/Base/SafeAllocator.h @@ -1,4 +1,4 @@ /* - * Copyright (c) 2011 Remko Tronçon + * Copyright (c) 2011-2014 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. @@ -10,5 +10,9 @@ #include <algorithm> +#include <Swiften/Base/API.h> + namespace Swift { + void secureZeroMemory(char* memory, size_t numberOfBytes); + template<typename T> class SafeAllocator : public std::allocator<T> { @@ -18,13 +22,15 @@ namespace Swift { }; - SafeAllocator() throw() {} - SafeAllocator(const SafeAllocator&) throw() : std::allocator<T>() {} - template <class U> SafeAllocator(const SafeAllocator<U>&) throw() {} - ~SafeAllocator() throw() {} + SafeAllocator() SWIFTEN_NOEXCEPT {} + SafeAllocator(const SafeAllocator&) SWIFTEN_NOEXCEPT : std::allocator<T>() {} + template <class U> SafeAllocator(const SafeAllocator<U>&) SWIFTEN_NOEXCEPT {} + ~SafeAllocator() SWIFTEN_NOEXCEPT {} void deallocate (T* p, size_t num) { - std::fill(reinterpret_cast<char*>(p), reinterpret_cast<char*>(p + num), 0); + secureZeroMemory(reinterpret_cast<char*>(p), num); std::allocator<T>::deallocate(p, num); } + + SWIFTEN_DEFAULT_COPY_ASSIGMNENT_OPERATOR(SafeAllocator) }; -}; +} |