Fix _root checking inconsistency in xml_document::destroy

git-svn-id: http://pugixml.googlecode.com/svn/trunk@955 99668b35-9821-0410-8761-19e4c4f06640
This commit is contained in:
arseny.kapoulkine@gmail.com 2013-08-02 02:43:13 +00:00
parent 888934dac6
commit 48600c3a9d

View File

@ -5220,6 +5220,8 @@ namespace pugi
PUGI__FN void xml_document::create()
{
assert(!_root);
// initialize sentinel page
PUGI__STATIC_ASSERT(offsetof(impl::xml_memory_page, data) + sizeof(impl::xml_document_struct) + impl::xml_memory_page_alignment <= sizeof(_memory));
@ -5242,6 +5244,8 @@ namespace pugi
PUGI__FN void xml_document::destroy()
{
assert(_root);
// destroy static storage
if (_buffer)
{
@ -5256,12 +5260,9 @@ namespace pugi
}
// destroy dynamic storage, leave sentinel page (it's in static memory)
if (_root)
{
impl::xml_memory_page* root_page = reinterpret_cast<impl::xml_memory_page*>(_root->header & impl::xml_memory_page_pointer_mask);
assert(root_page && !root_page->prev && !root_page->memory);
// destroy all pages
for (impl::xml_memory_page* page = root_page->next; page; )
{
impl::xml_memory_page* next = page->next;
@ -5271,14 +5272,8 @@ namespace pugi
page = next;
}
// cleanup root page
root_page->allocator = 0;
root_page->next = 0;
root_page->busy_size = root_page->freed_size = 0;
_root = 0;
}
}
#ifndef PUGIXML_NO_STL
PUGI__FN xml_parse_result xml_document::load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options, xml_encoding encoding)
@ -5403,6 +5398,8 @@ namespace pugi
PUGI__FN xml_node xml_document::document_element() const
{
assert(_root);
for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling)
if ((i->header & impl::xml_memory_page_type_mask) + 1 == node_element)
return xml_node(i);