Fix node_pi memory leak

This commit is contained in:
Arseny Kapoulkine 2015-04-22 08:38:52 -07:00
parent 4223b4a3f0
commit 3643b505a6
2 changed files with 27 additions and 0 deletions

View File

@ -1163,6 +1163,14 @@ PUGI__NS_BEGIN
if (n->header & impl::xml_memory_page_contents_allocated_mask)
alloc.deallocate_string(n->contents);
if (PUGI__NODETYPE(n) == node_pi)
{
xml_node_pi_struct* pn = static_cast<xml_node_pi_struct*>(n);
if (pn->pi_header & impl::xml_memory_page_contents_allocated_mask)
alloc.deallocate_string(pn->pi_value);
}
for (xml_attribute_struct* attr = n->first_attribute; attr; )
{
xml_attribute_struct* next = attr->next_attribute;

View File

@ -948,6 +948,25 @@ TEST(dom_node_memory_limit)
}
}
TEST(dom_node_memory_limit_pi)
{
const unsigned int length = 65536;
static char_t string[length + 1];
for (unsigned int i = 0; i < length; ++i) string[i] = 'a';
string[length] = 0;
test_runner::_memory_fail_threshold = 32768 * 2 + sizeof(string);
xml_document doc;
for (int j = 0; j < 32; ++j)
{
CHECK(doc.append_child(node_pi).set_value(string));
CHECK(doc.remove_child(doc.first_child()));
}
}
TEST(dom_node_doctype_top_level)
{
xml_document doc;