hdac SDK
SDK for hdac blockchain development
zero_after_free_allocator.h
1 #ifndef ZERO_AFTER_FREE_ALLOCATOR_H
2 #define ZERO_AFTER_FREE_ALLOCATOR_H
3 
4 #include <openssl/crypto.h> // for OPENSSL_cleanse()
5 
6 //
7 // Allocator that clears its contents before deletion.
8 //
9 template <typename T>
10 struct zero_after_free_allocator : public std::allocator<T> {
11  // MSVC8 default copy constructor is broken
12  typedef std::allocator<T> base;
13  typedef typename base::size_type size_type;
14  typedef typename base::difference_type difference_type;
15  typedef typename base::pointer pointer;
16  typedef typename base::const_pointer const_pointer;
17  typedef typename base::reference reference;
18  typedef typename base::const_reference const_reference;
19  typedef typename base::value_type value_type;
20  zero_after_free_allocator() throw() {}
21  zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {}
22  template <typename U>
24  {
25  }
26  ~zero_after_free_allocator() throw() {}
27  template <typename _Other>
28  struct rebind {
30  };
31 
32  void deallocate(T* p, std::size_t n)
33  {
34  if (p != NULL)
35  OPENSSL_cleanse(p, sizeof(T) * n);
36  std::allocator<T>::deallocate(p, n);
37  }
38 };
39 
40 #endif
Definition: zero_after_free_allocator.h:10
Definition: zero_after_free_allocator.h:28