Merge branch '0.4.x' into 0.5.0.x
authorLuke Dashjr <luke-jr+git@utopios.org>
Thu, 5 Jan 2012 23:17:58 +0000 (18:17 -0500)
committerLuke Dashjr <luke-jr+git@utopios.org>
Thu, 5 Jan 2012 23:17:58 +0000 (18:17 -0500)
1  2 
src/serialize.h

diff --combined src/serialize.h
@@@ -30,8 -30,7 +30,8 @@@ typedef unsigned long long  uint64
  #define for  if (false) ; else for
  #endif
  
 -#ifdef __WXMSW__
 +#ifdef WIN32
 +#include <windows.h>
  // This is used to attempt to keep keying material out of swap
  // Note that VirtualLock does not provide this as a guarantee on Windows,
  // but, in practice, memory that has been VirtualLock'd almost never gets written to
@@@ -60,7 -59,7 +60,7 @@@ class CDataStream
  class CAutoFile;
  static const unsigned int MAX_SIZE = 0x02000000;
  
 -static const int VERSION = 40300;
 +static const int VERSION = 50003;
  static const char* pszSubVer = "";
  static const bool VERSION_IS_BETA = true;
  
@@@ -829,6 -828,38 +829,38 @@@ struct secure_allocator : public std::a
  };
  
  
+ //
+ // 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.
  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;