llvm.org GIT mirror llvm / 6caf087
Unlink nodes instead of copying, to avoid memory problems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309151 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Beckmann 2 years ago
1 changed file(s) with 7 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
9292 Error treeMerge(XMLNodeImpl OriginalRoot, XMLNodeImpl AdditionalRoot) {
9393 #if LLVM_LIBXML2_ENABLED
9494 XMLNodeImpl AdditionalFirstChild = AdditionalRoot->children;
95 xmlNode StoreNext;
9596 for (XMLNodeImpl Child = AdditionalFirstChild; Child; Child = Child->next) {
9697 XMLNodeImpl OriginalChildWithName;
9798 if (!isMergeableElement(Child->name) ||
9899 !(OriginalChildWithName =
99100 getChildWithName(OriginalRoot, Child->name))) {
100 XMLNodeImpl NewChild = xmlCopyNode(Child, 1);
101 if (!NewChild)
102 return make_error(Twine("error when copying ") +
101 StoreNext.next = Child->next;
102 xmlUnlinkNode(Child);
103 if (!xmlAddChild(OriginalRoot, Child))
104 return make_error(Twine("could not merge ") +
103105 FROM_XML_CHAR(Child->name));
104 if (NewChild->ns)
105 xmlFreeNs(NewChild->ns); // xmlCopyNode explicitly defines default
106 // namespace, undo this here.
107 if (!xmlAddChild(OriginalRoot, NewChild))
108 return make_error(Twine("could not merge ") +
109 FROM_XML_CHAR(NewChild->name));
106 Child = &StoreNext;
110107 } else if (auto E = treeMerge(OriginalChildWithName, Child)) {
111108 return E;
112109 }
166163 return E;
167164 }
168165 } else {
169 XMLNodeImpl NewChild = xmlCopyNode(AdditionalRoot, 1);
170 if (!NewChild)
171 return make_error("could not copy manifest");
172 if (!xmlAddChild(CombinedRoot, NewChild))
173 return make_error("could not append manifest");
166 return make_error("multiple root nodes");
174167 }
175168 }
176169 MergedDocs.push_back(ManifestXML);