sanitizing_allocator is a child of std::allocator again implementing deallocation the proper way now

This commit is contained in:
Simon Rozman 2016-05-18 07:38:55 +02:00
parent f6029b2f04
commit 40d9d907d6

View File

@ -792,20 +792,10 @@ namespace winstd
/// Use for security sensitive data memory storage only. /// Use for security sensitive data memory storage only.
/// ///
template<class _Ty> template<class _Ty>
class sanitizing_allocator : public std::_Allocator_base<_Ty> class sanitizing_allocator : public std::allocator<_Ty>
{ {
public: public:
typedef std::_Allocator_base<_Ty> _Mybase; typedef std::allocator<_Ty> _Mybase;
typedef typename _Mybase::value_type value_type;
typedef value_type _FARQ *pointer;
typedef value_type _FARQ& reference;
typedef const value_type _FARQ *const_pointer;
typedef const value_type _FARQ& const_reference;
typedef _SIZT size_type;
typedef _PDFT difference_type;
/// ///
/// Convert this type to sanitizing_allocator<_Other> /// Convert this type to sanitizing_allocator<_Other>
@ -817,28 +807,10 @@ namespace winstd
}; };
///
/// Return address of mutable _Val
///
inline pointer address(_In_ reference _Val) const
{
return ((pointer) &(char&)_Val);
}
///
/// Return address of nonmutable _Val
///
inline const_pointer address(_In_ const_reference _Val) const
{
return ((const_pointer) &(char&)_Val);
}
/// ///
/// Construct default allocator /// Construct default allocator
/// ///
inline sanitizing_allocator() inline sanitizing_allocator() : _Mybase()
{ {
} }
@ -846,26 +818,17 @@ namespace winstd
/// ///
/// Construct by copying /// Construct by copying
/// ///
inline sanitizing_allocator(_In_ const sanitizing_allocator<_Ty>&) inline sanitizing_allocator(_In_ const sanitizing_allocator<_Ty> &_Othr) : _Mybase(_Othr)
{ {
} }
/// ///
/// Construct from a related allocator /// Construct from a related allocator
template<class _Other>
inline sanitizing_allocator(_In_ const sanitizing_allocator<_Other>&)
{
}
///
/// Assign from a related allocator
/// ///
template<class _Other> template<class _Other>
inline sanitizing_allocator<_Ty>& operator=(_In_ const sanitizing_allocator<_Other>&) inline sanitizing_allocator(_In_ const sanitizing_allocator<_Other> &_Othr) : _Mybase(_Othr)
{ {
return (*this);
} }
@ -876,80 +839,7 @@ namespace winstd
{ {
// Sanitize then free. // Sanitize then free.
SecureZeroMemory(_Ptr, _Size); SecureZeroMemory(_Ptr, _Size);
::operator delete(_Ptr); _Mybase::deallocate(_Ptr, _Size);
}
///
/// Allocate array of _Count elements
///
inline pointer allocate(_In_ size_type _Count)
{
void *_Ptr = 0;
if (_Count <= 0)
_Count = 0;
else if (((_SIZT)(-1)/sizeof(_Ty) < _Count) || (_Ptr = ::operator new(_Count * sizeof(_Ty))) == 0)
_THROW_NCEE(bad_alloc, 0);
return ((_Ty _FARQ *)_Ptr);
}
///
/// Allocate array of _Count elements
///
inline pointer allocate(_In_ size_type _Count, _In_ const void _FARQ *)
{
return (allocate(_Count));
}
///
/// Construct object at _Ptr with value _Val
///
inline void construct(_In_ pointer _Ptr, _In_ const _Ty& _Val)
{
void _FARQ *_Vptr = _Ptr;
::new (_Vptr)_Ty1(_STD forward<_Ty2>(_Val));
}
///
/// Construct object at _Ptr with value _Val
///
inline void construct(_In_ pointer _Ptr, _In_ _Ty&& _Val)
{
::new ((void _FARQ *)_Ptr) _Ty(_STD forward<_Ty>(_Val));
}
///
/// Construct object at _Ptr with value _Val
///
template<class _Other>
inline void construct(_In_ pointer _Ptr, _In_ _Other&& _Val)
{
::new ((void _FARQ *)_Ptr) _Ty(_STD forward<_Other>(_Val));
}
///
/// Destroy object at _Ptr
///
inline void destroy(_In_ pointer _Ptr)
{
_Ptr->~_Ty();
}
///
/// Estimate maximum array size
///
inline _SIZT max_size() const
{
_SIZT _Count = (_SIZT)(-1) / sizeof (_Ty);
return (0 < _Count ? _Count : 1);
} }
}; };