From 505621faa4f61f4dbc83724911aad950884efff0 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 24 Feb 2025 12:57:00 -0800 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?= =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 [skip ci] --- .../WindowsManifest/WindowsManifestMerger.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp index cdd63686d4711..b9e9d0768a96d 100644 --- a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp +++ b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp @@ -32,6 +32,7 @@ void WindowsManifestError::log(raw_ostream &OS) const { OS << Msg; } class WindowsManifestMerger::WindowsManifestMergerImpl { public: + ~WindowsManifestMergerImpl(); Error merge(MemoryBufferRef Manifest); std::unique_ptr getMergedManifest(); @@ -43,8 +44,11 @@ class WindowsManifestMerger::WindowsManifestMergerImpl { void operator()(xmlChar *Ptr) { xmlFree(Ptr); } void operator()(xmlDoc *Ptr) { xmlFreeDoc(Ptr); } }; + + + xmlDocPtr CombinedDoc = nullptr; - std::vector> MergedDocs; + std::vector MergedDocs; bool Merged = false; int BufferSize = 0; std::unique_ptr Buffer; @@ -610,6 +614,11 @@ static void checkAndStripPrefixes(xmlNodePtr Node, } } +WindowsManifestMerger::WindowsManifestMergerImpl::~WindowsManifestMergerImpl() { + for (auto &Doc : MergedDocs) + xmlFreeDoc(Doc); +} + Error WindowsManifestMerger::WindowsManifestMergerImpl::merge( MemoryBufferRef Manifest) { if (Merged) @@ -620,17 +629,17 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge( "attempted to merge empty manifest"); xmlSetGenericErrorFunc((void *)this, WindowsManifestMergerImpl::errorCallback); - std::unique_ptr ManifestXML(xmlReadMemory( + xmlDocPtr ManifestXML = xmlReadMemory( Manifest.getBufferStart(), Manifest.getBufferSize(), "manifest.xml", - nullptr, XML_PARSE_NOBLANKS | XML_PARSE_NODICT)); + nullptr, XML_PARSE_NOBLANKS | XML_PARSE_NODICT); xmlSetGenericErrorFunc(nullptr, nullptr); if (auto E = getParseError()) return E; - xmlNodePtr AdditionalRoot = xmlDocGetRootElement(ManifestXML.get()); + xmlNodePtr AdditionalRoot = xmlDocGetRootElement(ManifestXML); stripComments(AdditionalRoot); setAttributeNamespaces(AdditionalRoot); if (CombinedDoc == nullptr) { - CombinedDoc = ManifestXML.get(); + CombinedDoc = ManifestXML; } else { xmlNodePtr CombinedRoot = xmlDocGetRootElement(CombinedDoc); if (!xmlStringsEqual(CombinedRoot->name, AdditionalRoot->name) || @@ -642,7 +651,7 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge( return E; } } - MergedDocs.push_back(std::move(ManifestXML)); + MergedDocs.push_back(ManifestXML); return Error::success(); } From 0c15e85a214f62e76a2014e1173039c1c1a84d6d Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 24 Feb 2025 12:58:50 -0800 Subject: [PATCH 2/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?= =?UTF-8?q?anges=20introduced=20through=20rebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 [skip ci] --- .../WindowsManifest/WindowsManifestMerger.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp index cdd63686d4711..b9e9d0768a96d 100644 --- a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp +++ b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp @@ -32,6 +32,7 @@ void WindowsManifestError::log(raw_ostream &OS) const { OS << Msg; } class WindowsManifestMerger::WindowsManifestMergerImpl { public: + ~WindowsManifestMergerImpl(); Error merge(MemoryBufferRef Manifest); std::unique_ptr getMergedManifest(); @@ -43,8 +44,11 @@ class WindowsManifestMerger::WindowsManifestMergerImpl { void operator()(xmlChar *Ptr) { xmlFree(Ptr); } void operator()(xmlDoc *Ptr) { xmlFreeDoc(Ptr); } }; + + + xmlDocPtr CombinedDoc = nullptr; - std::vector> MergedDocs; + std::vector MergedDocs; bool Merged = false; int BufferSize = 0; std::unique_ptr Buffer; @@ -610,6 +614,11 @@ static void checkAndStripPrefixes(xmlNodePtr Node, } } +WindowsManifestMerger::WindowsManifestMergerImpl::~WindowsManifestMergerImpl() { + for (auto &Doc : MergedDocs) + xmlFreeDoc(Doc); +} + Error WindowsManifestMerger::WindowsManifestMergerImpl::merge( MemoryBufferRef Manifest) { if (Merged) @@ -620,17 +629,17 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge( "attempted to merge empty manifest"); xmlSetGenericErrorFunc((void *)this, WindowsManifestMergerImpl::errorCallback); - std::unique_ptr ManifestXML(xmlReadMemory( + xmlDocPtr ManifestXML = xmlReadMemory( Manifest.getBufferStart(), Manifest.getBufferSize(), "manifest.xml", - nullptr, XML_PARSE_NOBLANKS | XML_PARSE_NODICT)); + nullptr, XML_PARSE_NOBLANKS | XML_PARSE_NODICT); xmlSetGenericErrorFunc(nullptr, nullptr); if (auto E = getParseError()) return E; - xmlNodePtr AdditionalRoot = xmlDocGetRootElement(ManifestXML.get()); + xmlNodePtr AdditionalRoot = xmlDocGetRootElement(ManifestXML); stripComments(AdditionalRoot); setAttributeNamespaces(AdditionalRoot); if (CombinedDoc == nullptr) { - CombinedDoc = ManifestXML.get(); + CombinedDoc = ManifestXML; } else { xmlNodePtr CombinedRoot = xmlDocGetRootElement(CombinedDoc); if (!xmlStringsEqual(CombinedRoot->name, AdditionalRoot->name) || @@ -642,7 +651,7 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge( return E; } } - MergedDocs.push_back(std::move(ManifestXML)); + MergedDocs.push_back(ManifestXML); return Error::success(); }