diff options
author | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-08-03 08:05:32 +0000 |
---|---|---|
committer | arseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640> | 2010-08-03 08:05:32 +0000 |
commit | f533923f1fe5b1b75771ced133858d6b23cde512 (patch) | |
tree | a87928d7e6084cf8db92a2c8410e06e251f11afb /src | |
parent | 085584aa30b79e7755ffdf50882f7decfd4336be (diff) |
XPath: Fixed leaks in case query compilation failed
git-svn-id: http://pugixml.googlecode.com/svn/trunk@621 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'src')
-rw-r--r-- | src/pugixml.hpp | 2 | ||||
-rw-r--r-- | src/pugixpath.cpp | 18 |
2 files changed, 7 insertions, 13 deletions
diff --git a/src/pugixml.hpp b/src/pugixml.hpp index 6a5f7e4..d79d128 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -369,8 +369,6 @@ namespace pugi xpath_allocator* m_alloc; xpath_ast_node* m_root; - void compile(const char_t* query); - public: /** * Constructor from string with XPath expression. 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 <algorithm> +#include <memory> #include <string> // 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<xpath_allocator> 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 |