changeset 7299:e0f305cf3f08 draft

(svn r10647) -Fix: AutoPtrT::operator =() didn't delete old object
author KUDr <KUDr@openttd.org>
date Sat, 21 Jul 2007 14:01:12 +0000
parents b30b64f784db
children c0d2ce6f2097
files src/misc/autoptr.hpp
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/misc/autoptr.hpp
+++ b/src/misc/autoptr.hpp
@@ -81,8 +81,16 @@
 	/** assignment operator */
 	FORCEINLINE AutoPtrT& operator = (const AutoPtrT& src)
 	{
+		/* Save original pointer and replace it with the given one to avoid recursive calls. */
+		T* p = m_p;
 		m_p = src.m_p;
+
 		if (m_p != NULL) src.m_p = NULL;
+
+		if (p != NULL) {
+			/* Now we can safely delete the old one. */
+			delete p;
+		}
 		return *this;
 	}