@@ -40,14 +40,14 @@ class WindowsManifestMerger::WindowsManifestMergerImpl {
4040 static void errorCallback (void *Ctx, const char *Format, ...);
4141 Error getParseError ();
4242#if LLVM_ENABLE_LIBXML2
43- xmlDocPtr CombinedDoc = nullptr ;
44- std::vector<xmlDocPtr> MergedDocs;
45-
46- bool Merged = false ;
4743 struct XmlDeleter {
4844 void operator ()(xmlChar *Ptr) { xmlFree (Ptr); }
4945 void operator ()(xmlDoc *Ptr) { xmlFreeDoc (Ptr); }
5046 };
47+ xmlDocPtr CombinedDoc = nullptr ;
48+ std::vector<std::unique_ptr<xmlDoc, XmlDeleter>> MergedDocs;
49+
50+ bool Merged = false ;
5151 int BufferSize = 0 ;
5252 std::unique_ptr<xmlChar, XmlDeleter> Buffer;
5353#endif
@@ -613,8 +613,6 @@ static void checkAndStripPrefixes(xmlNodePtr Node,
613613}
614614
615615WindowsManifestMerger::WindowsManifestMergerImpl::~WindowsManifestMergerImpl () {
616- for (auto &Doc : MergedDocs)
617- xmlFreeDoc (Doc);
618616}
619617
620618Error WindowsManifestMerger::WindowsManifestMergerImpl::merge (
@@ -627,17 +625,17 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
627625 " attempted to merge empty manifest" );
628626 xmlSetGenericErrorFunc ((void *)this ,
629627 WindowsManifestMergerImpl::errorCallback);
630- xmlDocPtr ManifestXML = xmlReadMemory (
628+ std::unique_ptr<xmlDoc, XmlDeleter> ManifestXML ( xmlReadMemory (
631629 Manifest.getBufferStart (), Manifest.getBufferSize (), " manifest.xml" ,
632- nullptr , XML_PARSE_NOBLANKS | XML_PARSE_NODICT);
630+ nullptr , XML_PARSE_NOBLANKS | XML_PARSE_NODICT)) ;
633631 xmlSetGenericErrorFunc (nullptr , nullptr );
634632 if (auto E = getParseError ())
635633 return E;
636- xmlNodePtr AdditionalRoot = xmlDocGetRootElement (ManifestXML);
634+ xmlNodePtr AdditionalRoot = xmlDocGetRootElement (ManifestXML. get () );
637635 stripComments (AdditionalRoot);
638636 setAttributeNamespaces (AdditionalRoot);
639637 if (CombinedDoc == nullptr ) {
640- CombinedDoc = ManifestXML;
638+ CombinedDoc = ManifestXML. get () ;
641639 } else {
642640 xmlNodePtr CombinedRoot = xmlDocGetRootElement (CombinedDoc);
643641 if (!xmlStringsEqual (CombinedRoot->name , AdditionalRoot->name ) ||
@@ -649,7 +647,7 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
649647 return E;
650648 }
651649 }
652- MergedDocs.push_back (ManifestXML);
650+ MergedDocs.push_back (std::move ( ManifestXML) );
653651 return Error::success ();
654652}
655653
0 commit comments