XPath: Fixed leaks in case query compilation failed

git-svn-id: http://pugixml.googlecode.com/svn/trunk@621 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
arseny.kapoulkine 2010-08-03 08:05:32 +00:00
parent 085584aa30
commit f533923f1f
2 changed files with 7 additions and 13 deletions

View File

@ -369,8 +369,6 @@ namespace pugi
xpath_allocator* m_alloc; xpath_allocator* m_alloc;
xpath_ast_node* m_root; xpath_ast_node* m_root;
void compile(const char_t* query);
public: public:
/** /**
* Constructor from string with XPath expression. * Constructor from string with XPath expression.

View File

@ -49,6 +49,7 @@ typedef __int32 int32_t;
#endif #endif
#include <algorithm> #include <algorithm>
#include <memory>
#include <string> #include <string>
// String utilities prototypes // String utilities prototypes
@ -3359,7 +3360,12 @@ namespace pugi
xpath_query::xpath_query(const char_t* query): m_alloc(0), m_root(0) 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_parser p(query, *alloc);
m_root = p.parse();
m_alloc = alloc.release();
} }
xpath_query::~xpath_query() xpath_query::~xpath_query()
@ -3367,16 +3373,6 @@ namespace pugi
delete m_alloc; delete m_alloc;
} }
void xpath_query::compile(const char_t* 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 xpath_value_type xpath_query::return_type() const
{ {
if (!m_root) return xpath_type_none; if (!m_root) return xpath_type_none;