Skip to content

Reland "[llvm-mt] Use XmlDeleter to free xmlFreeDoc"" #128579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions llvm/lib/WindowsManifest/WindowsManifestMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void WindowsManifestError::log(raw_ostream &OS) const { OS << Msg; }

class WindowsManifestMerger::WindowsManifestMergerImpl {
public:
~WindowsManifestMergerImpl();
Error merge(MemoryBufferRef Manifest);
std::unique_ptr<MemoryBuffer> getMergedManifest();

Expand All @@ -45,7 +44,7 @@ class WindowsManifestMerger::WindowsManifestMergerImpl {
void operator()(xmlDoc *Ptr) { xmlFreeDoc(Ptr); }
};
xmlDocPtr CombinedDoc = nullptr;
std::vector<xmlDocPtr> MergedDocs;
std::vector<std::unique_ptr<xmlDoc, XmlDeleter>> MergedDocs;
bool Merged = false;
int BufferSize = 0;
std::unique_ptr<xmlChar, XmlDeleter> Buffer;
Expand Down Expand Up @@ -611,11 +610,6 @@ static void checkAndStripPrefixes(xmlNodePtr Node,
}
}

WindowsManifestMerger::WindowsManifestMergerImpl::~WindowsManifestMergerImpl() {
for (auto &Doc : MergedDocs)
xmlFreeDoc(Doc);
}

Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
MemoryBufferRef Manifest) {
if (Merged)
Expand All @@ -626,17 +620,17 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
"attempted to merge empty manifest");
xmlSetGenericErrorFunc((void *)this,
WindowsManifestMergerImpl::errorCallback);
xmlDocPtr ManifestXML = xmlReadMemory(
std::unique_ptr<xmlDoc, XmlDeleter> 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);
xmlNodePtr AdditionalRoot = xmlDocGetRootElement(ManifestXML.get());
stripComments(AdditionalRoot);
setAttributeNamespaces(AdditionalRoot);
if (CombinedDoc == nullptr) {
CombinedDoc = ManifestXML;
CombinedDoc = ManifestXML.get();
} else {
xmlNodePtr CombinedRoot = xmlDocGetRootElement(CombinedDoc);
if (!xmlStringsEqual(CombinedRoot->name, AdditionalRoot->name) ||
Expand All @@ -648,7 +642,7 @@ Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
return E;
}
}
MergedDocs.push_back(ManifestXML);
MergedDocs.push_back(std::move(ManifestXML));
return Error::success();
}

Expand Down Expand Up @@ -682,9 +676,6 @@ bool windows_manifest::isAvailable() { return true; }

#else

WindowsManifestMerger::WindowsManifestMergerImpl::~WindowsManifestMergerImpl() {
}

Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
MemoryBufferRef Manifest) {
return make_error<WindowsManifestError>("no libxml2");
Expand Down