aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2012-01-05 18:17:58 -0500
committerLuke Dashjr <luke-jr+git@utopios.org>2012-01-05 18:17:58 -0500
commit780a1823177e851f75b6f22e7f7bfe49b7938862 (patch)
treebe80fefe4505c3c1bc85544b0cf9d3da642eaa1c
parent45099b19daea9b78bf9823fab8d930211f738d7d (diff)
parent99e9601e805c009b301c7cb29d541858507ae095 (diff)
downloadbitcoin-780a1823177e851f75b6f22e7f7bfe49b7938862.tar.xz
Merge branch '0.4.x' into 0.5.0.x
-rw-r--r--src/serialize.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/serialize.h b/src/serialize.h
index fdfd6346e9..0f075a5bf1 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -829,6 +829,38 @@ struct secure_allocator : public std::allocator<T>
};
+//
+// Allocator that clears its contents before deletion.
+//
+template<typename T>
+struct zero_after_free_allocator : public std::allocator<T>
+{
+ // MSVC8 default copy constructor is broken
+ typedef std::allocator<T> base;
+ typedef typename base::size_type size_type;
+ typedef typename base::difference_type difference_type;
+ typedef typename base::pointer pointer;
+ typedef typename base::const_pointer const_pointer;
+ typedef typename base::reference reference;
+ typedef typename base::const_reference const_reference;
+ typedef typename base::value_type value_type;
+ zero_after_free_allocator() throw() {}
+ zero_after_free_allocator(const zero_after_free_allocator& a) throw() : base(a) {}
+ template <typename U>
+ zero_after_free_allocator(const zero_after_free_allocator<U>& a) throw() : base(a) {}
+ ~zero_after_free_allocator() throw() {}
+ template<typename _Other> struct rebind
+ { typedef zero_after_free_allocator<_Other> other; };
+
+ void deallocate(T* p, std::size_t n)
+ {
+ if (p != NULL)
+ memset(p, 0, sizeof(T) * n);
+ std::allocator<T>::deallocate(p, n);
+ }
+};
+
+
//
// Double ended buffer combining vector and stream-like interfaces.
@@ -838,7 +870,7 @@ struct secure_allocator : public std::allocator<T>
class CDataStream
{
protected:
- typedef std::vector<char, secure_allocator<char> > vector_type;
+ typedef std::vector<char, zero_after_free_allocator<char> > vector_type;
vector_type vch;
unsigned int nReadPos;
short state;