From 95db3cc2f971eecd22766db7fa411f7c4fe5f1bd Mon Sep 17 00:00:00 2001 From: vl Date: Mon, 17 May 2010 14:51:04 +0200 Subject: [PATCH] Fixed: #906 move code from .h to .cpp to resolve a libxml allocator problem --- .../common/src/game_share/xml_auto_ptr.cpp | 14 ++++++------- .../common/src/game_share/xml_auto_ptr.h | 21 ++++++++++++++++--- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/code/ryzom/common/src/game_share/xml_auto_ptr.cpp b/code/ryzom/common/src/game_share/xml_auto_ptr.cpp index ebe4113e6..4fcdb9543 100644 --- a/code/ryzom/common/src/game_share/xml_auto_ptr.cpp +++ b/code/ryzom/common/src/game_share/xml_auto_ptr.cpp @@ -14,9 +14,13 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . - +/* + * Completely implemented in xml_auto_ptr.h + */ #include "stdpch.h" + +/* #include "xml_auto_ptr.h" #include @@ -45,10 +49,4 @@ CXMLAutoPtr &CXMLAutoPtr::operator = (const char *other) return *this; } - - - - - - - +*/ diff --git a/code/ryzom/common/src/game_share/xml_auto_ptr.h b/code/ryzom/common/src/game_share/xml_auto_ptr.h index 8744b9ae4..70a011a00 100644 --- a/code/ryzom/common/src/game_share/xml_auto_ptr.h +++ b/code/ryzom/common/src/game_share/xml_auto_ptr.h @@ -28,7 +28,7 @@ class CXMLAutoPtr public: CXMLAutoPtr(const char *value = NULL) : _Value(value) {} CXMLAutoPtr(const unsigned char *value) : _Value((const char *) value) {} - ~CXMLAutoPtr(); + ~CXMLAutoPtr() { destroy(); } operator const char *() const { return _Value; } operator bool() const { return _Value != NULL; } operator std::string() const { return std::string(_Value); } @@ -36,7 +36,14 @@ public: operator const unsigned char *() const { return (const unsigned char *) _Value; } const char operator * () const { nlassert(_Value); return *_Value; } /// NB : This remove previous owned pointer with xmlFree - CXMLAutoPtr &operator = (const char *other); + CXMLAutoPtr &operator = (const char *other) + { + if (other == _Value) return *this; + destroy(); + _Value = other; + return *this; + } + CXMLAutoPtr &operator = (const unsigned char *other) { *this = (const char *) other; @@ -47,7 +54,15 @@ public: private: const char *_Value; private: - void destroy(); + void destroy() + { + if (_Value) + { + xmlFree(const_cast(_Value)); + _Value = NULL; + } + } + // We'd rather avoid problems CXMLAutoPtr(const CXMLAutoPtr &/* other */) {