Raven Core  3.0.0
P2P Digital Currency
zeroafterfree.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef RAVEN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H
8 #define RAVEN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H
9 
10 #include "support/cleanse.h"
11 
12 #include <memory>
13 #include <vector>
14 
15 template <typename T>
16 struct zero_after_free_allocator : public std::allocator<T> {
17  // MSVC8 default copy constructor is broken
18  typedef std::allocator<T> base;
19  typedef typename base::size_type size_type;
20  typedef typename base::difference_type difference_type;
21  typedef typename base::pointer pointer;
22  typedef typename base::const_pointer const_pointer;
23  typedef typename base::reference reference;
24  typedef typename base::const_reference const_reference;
25  typedef typename base::value_type value_type;
28  template <typename U>
30  {
31  }
33  template <typename _Other>
34  struct rebind {
36  };
37 
38  void deallocate(T* p, std::size_t n)
39  {
40  if (p != nullptr)
41  memory_cleanse(p, sizeof(T) * n);
42  std::allocator<T>::deallocate(p, n);
43  }
44 };
45 
46 // Byte-vector that clears its contents before deletion.
47 typedef std::vector<char, zero_after_free_allocator<char> > CSerializeData;
48 
49 #endif // RAVEN_SUPPORT_ALLOCATORS_ZEROAFTERFREE_H
base::const_pointer const_pointer
Definition: zeroafterfree.h:22
~zero_after_free_allocator() noexcept
Definition: zeroafterfree.h:32
base::value_type value_type
Definition: zeroafterfree.h:25
void memory_cleanse(void *ptr, size_t len)
Definition: cleanse.cpp:28
zero_after_free_allocator< _Other > other
Definition: zeroafterfree.h:35
base::const_reference const_reference
Definition: zeroafterfree.h:24
zero_after_free_allocator() noexcept
Definition: zeroafterfree.h:26
base::size_type size_type
Definition: zeroafterfree.h:19
zero_after_free_allocator(const zero_after_free_allocator< U > &a) noexcept
Definition: zeroafterfree.h:29
std::allocator< T > base
Definition: zeroafterfree.h:18
void deallocate(T *p, std::size_t n)
Definition: zeroafterfree.h:38
std::vector< char, zero_after_free_allocator< char > > CSerializeData
Definition: zeroafterfree.h:47
base::difference_type difference_type
Definition: zeroafterfree.h:20
zero_after_free_allocator(const zero_after_free_allocator &a) noexcept
Definition: zeroafterfree.h:27
base::reference reference
Definition: zeroafterfree.h:23