Permalink
Browse files

Workaround for segfault caused by addChild(): child now points to a n…

…ew unrelated xmlNode to avoid the crashes. DO NOT suppose child is the newly added child: in some cases it's not.
  • Loading branch information...
thomas-riccardi committed Jul 18, 2012
1 parent f4707b5 commit 4320d506e2cc08c117821a7fae36ffb05fe2db32
Showing with 7 additions and 1 deletion.
  1. +7 −1 src/xml_element.cc
View
@@ -326,7 +326,13 @@ XmlElement::get_attrs() {
void
XmlElement::add_child(XmlElement* child) {
- xmlAddChild(xml_obj, child->xml_obj);
+ xmlNodePtr node = xmlAddChild(xml_obj, child->xml_obj);
+ if (node != child->xml_obj)
+ {
+ // xmlAddChild deleted child->xml_obj by merging it with xml_obj last child
+ // recreate a valid xml_obj for child to avoid any memory issue
+ child->xml_obj = xmlNewDocText(xml_obj->doc, (const xmlChar*) "");
+ }
}
void

0 comments on commit 4320d50

Please sign in to comment.