[llvm] Revert "[llvm-mt] Use XmlDeleter to free xmlFreeDoc" (PR #128578)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 24 13:07:30 PST 2025


https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/128578

Reverts llvm/llvm-project#128472

Breaks build bots.

>From 575677da14eab5af89b9b7bc6c46740505c5db4c Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at gmail.com>
Date: Mon, 24 Feb 2025 13:07:08 -0800
Subject: [PATCH] Revert "[llvm-mt] Use XmlDeleter to free xmlFreeDoc
 (#128472)"

This reverts commit 53c08dfc18163ab50a94da344fd93fddac179495.
---
 .../WindowsManifest/WindowsManifestMerger.cpp  | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp b/llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
index cdd63686d4711..a85dcd2ae2859 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<MemoryBuffer> getMergedManifest();
 
@@ -44,7 +45,7 @@ class WindowsManifestMerger::WindowsManifestMergerImpl {
     void operator()(xmlDoc *Ptr) { xmlFreeDoc(Ptr); }
   };
   xmlDocPtr CombinedDoc = nullptr;
-  std::vector<std::unique_ptr<xmlDoc, XmlDeleter>> MergedDocs;
+  std::vector<xmlDocPtr> MergedDocs;
   bool Merged = false;
   int BufferSize = 0;
   std::unique_ptr<xmlChar, XmlDeleter> Buffer;
@@ -610,6 +611,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 +626,17 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
         "attempted to merge empty manifest");
   xmlSetGenericErrorFunc((void *)this,
                          WindowsManifestMergerImpl::errorCallback);
-  std::unique_ptr<xmlDoc, XmlDeleter> 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 +648,7 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
       return E;
     }
   }
-  MergedDocs.push_back(std::move(ManifestXML));
+  MergedDocs.push_back(ManifestXML);
   return Error::success();
 }
 



More information about the llvm-commits mailing list