diff options
author | Shaun McCance <shaunm@redhat.com> | 2017-10-25 12:10:03 -0400 |
---|---|---|
committer | Shaun McCance <shaunm@redhat.com> | 2017-10-25 12:10:03 -0400 |
commit | 9b84c007a73e8275ca45762f1bfa3ab7c3a852e2 (patch) | |
tree | 56ad0e600c407c767f081323a28951749b880fe4 | |
parent | 890f35998ba7f86bdc58227142309b8ecc618c10 (diff) | |
download | itstool-9b84c007a73e8275ca45762f1bfa3ab7c3a852e2.tar.gz |
Be more careful about libxml2 memory management
I think this fixes https://github.com/itstool/itstool/issues/17
-rwxr-xr-x | itstool.in | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -477,6 +477,7 @@ class Document (object): if load_dtd: ctxt.loadSubset(1) if keep_entities: + ctxt.loadSubset(1) ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD) ctxt.replaceEntities(0) else: @@ -1043,6 +1044,7 @@ class Document (object): if self._load_dtd: ctxt.loadSubset(1) if self._keep_entities: + ctxt.loadSubset(1) ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD) ctxt.replaceEntities(0) else: @@ -1069,7 +1071,9 @@ class Document (object): ph_node = msg.get_placeholder(child.name).node if self.has_child_elements(ph_node): self.merge_translations(translations, None, ph_node, strict=strict) - child.replaceNode(ph_node) + newnode = ph_node.copyNode(1) + newnode.setTreeDoc(self._doc) + child.replaceNode(newnode) else: repl = self.get_translated(ph_node, translations, strict=strict, lang=lang) child.replaceNode(repl) @@ -1084,10 +1088,15 @@ class Document (object): (lang + ' ') if lang is not None else '', msgstr.encode('utf-8'))) self._xml_err = '' + ctxt.doc().freeDoc() return node retnode = node.copyNode(2) + retnode.setTreeDoc(self._doc) for child in xml_child_iter(trnode): - retnode.addChild(child.copyNode(1)) + newnode = child.copyNode(1) + newnode.setTreeDoc(self._doc) + retnode.addChild(newnode) + ctxt.doc().freeDoc() return retnode |