From f533923f1fe5b1b75771ced133858d6b23cde512 Mon Sep 17 00:00:00 2001 From: "arseny.kapoulkine" Date: Tue, 3 Aug 2010 08:05:32 +0000 Subject: XPath: Fixed leaks in case query compilation failed git-svn-id: http://pugixml.googlecode.com/svn/trunk@621 99668b35-9821-0410-8761-19e4c4f06640 --- src/pugixpath.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/pugixpath.cpp') diff --git a/src/pugixpath.cpp b/src/pugixpath.cpp index e9b7bc0..56775af 100644 --- a/src/pugixpath.cpp +++ b/src/pugixpath.cpp @@ -49,6 +49,7 @@ typedef __int32 int32_t; #endif #include +#include #include // String utilities prototypes @@ -3359,22 +3360,17 @@ namespace pugi xpath_query::xpath_query(const char_t* query): m_alloc(0), m_root(0) { - compile(query); - } + std::auto_ptr alloc(new xpath_allocator); - xpath_query::~xpath_query() - { - delete m_alloc; + xpath_parser p(query, *alloc); + + m_root = p.parse(); + m_alloc = alloc.release(); } - void xpath_query::compile(const char_t* query) + xpath_query::~xpath_query() { delete m_alloc; - m_alloc = new xpath_allocator; - - xpath_parser p(query, *m_alloc); - - m_root = p.parse(); } xpath_value_type xpath_query::return_type() const -- cgit v1.2.3