Fix some memory errors (bug 5904, r=ds).

This commit is contained in:
David Anderson
2013-10-29 18:58:34 -04:00
parent 66dd3f08b1
commit 96d6cf8def
6 changed files with 37 additions and 23 deletions
+31 -14
View File
@@ -37,6 +37,7 @@
#if defined(_MSC_VER)
# include <intrin.h>
#endif
#include <am-moveable.h>
#define KE_32BIT
@@ -62,6 +63,18 @@ ReturnAndVoid(T &t)
return saved;
}
#if __cplusplus >= 201103L
# define KE_CXX11
#endif
#if defined(KE_CXX11)
# define KE_DELETE = delete
# define KE_OVERRIDE = override
#else
# define KE_DELETE
# define KE_OVERRIDE
#endif
// Wrapper that automatically deletes its contents. The pointer can be taken
// to avoid destruction.
template <typename T>
@@ -74,10 +87,15 @@ class AutoPtr
: t_(NULL)
{
}
explicit AutoPtr(T *t)
AutoPtr(T *t)
: t_(t)
{
}
AutoPtr(Moveable<AutoPtr<T> > &other)
{
t_ = other->t_;
other->t_ = NULL;
}
~AutoPtr() {
delete t_;
}
@@ -93,13 +111,24 @@ class AutoPtr
operator T *() const {
return t_;
}
void operator =(T *t) {
T *operator =(T *t) {
delete t_;
t_ = t;
return t_;
}
T *operator =(Moveable<AutoPtr<T> > &other) {
delete t_;
t_ = other->t_;
other->t_ = NULL;
return t_;
}
bool operator !() const {
return !t_;
}
private:
AutoPtr(const AutoPtr &other) KE_DELETE;
AutoPtr &operator =(const AutoPtr &other) KE_DELETE;
};
// Wrapper that automatically deletes its contents. The pointer can be taken
@@ -298,18 +327,6 @@ class StorageBuffer
};
};
#if __cplusplus >= 201103L
# define KE_CXX11
#endif
#if defined(KE_CXX11)
# define KE_DELETE delete
# define KE_OVERRIDE override
#else
# define KE_DELETE
# define KE_OVERRIDE
#endif
#if defined(_MSC_VER)
# define KE_SIZET_FMT "%Iu"
#elif defined(__GNUC__)