Permalink
Browse files

Merge pull request #148 from SYSTRAN/addchild_segfault

fix segfault caused by addChild()
  • Loading branch information...
2 parents 1d56d81 + 4320d50 commit 35088aa63006ebf3809f327396715c37a06311ca @defunctzombie defunctzombie committed Jul 26, 2012
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 35088aa

Please sign in to comment.