[PATCH] D37321: llvm-mt: Fix release of OutputDoc
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 1 11:30:43 PDT 2017
vitalybuka updated this revision to Diff 113562.
vitalybuka added a comment.
Redo
https://reviews.llvm.org/D37321
Files:
lib/WindowsManifest/WindowsManifestMerger.cpp
Index: lib/WindowsManifest/WindowsManifestMerger.cpp
===================================================================
--- lib/WindowsManifest/WindowsManifestMerger.cpp
+++ lib/WindowsManifest/WindowsManifestMerger.cpp
@@ -44,6 +44,14 @@
#if LLVM_LIBXML2_ENABLED
xmlDocPtr CombinedDoc = nullptr;
std::vector<xmlDocPtr> MergedDocs;
+
+ bool Merged = false;
+ struct XmlDeleter {
+ void operator()(xmlChar *Ptr) { xmlFree(Ptr); }
+ void operator()(xmlDoc *Ptr) { xmlFreeDoc(Ptr); }
+ };
+ int BufferSize = 0;
+ std::unique_ptr<xmlChar, XmlDeleter> Buffer;
#endif
bool ParseErrorOccurred = false;
};
@@ -613,14 +621,17 @@
Error WindowsManifestMerger::WindowsManifestMergerImpl::merge(
const MemoryBuffer &Manifest) {
+ if (Merged)
+ return make_error<WindowsManifestError>(
+ "merge after getMergedManifest is not supported");
if (Manifest.getBufferSize() == 0)
return make_error<WindowsManifestError>(
"attempted to merge empty manifest");
xmlSetGenericErrorFunc((void *)this,
WindowsManifestMergerImpl::errorCallback);
- xmlDocPtr ManifestXML =
- xmlReadMemory(Manifest.getBufferStart(), Manifest.getBufferSize(),
- "manifest.xml", nullptr, XML_PARSE_NOBLANKS);
+ xmlDocPtr ManifestXML = xmlReadMemory(
+ Manifest.getBufferStart(), Manifest.getBufferSize(), "manifest.xml",
+ nullptr, XML_PARSE_NOBLANKS | XML_PARSE_NODICT);
xmlSetGenericErrorFunc(nullptr, nullptr);
if (auto E = getParseError())
return E;
@@ -646,22 +657,29 @@
std::unique_ptr<MemoryBuffer>
WindowsManifestMerger::WindowsManifestMergerImpl::getMergedManifest() {
- unsigned char *XmlBuff;
- int BufferSize = 0;
- if (CombinedDoc) {
+ if (!Merged) {
+ Merged = true;
+
+ if (!CombinedDoc)
+ return nullptr;
+
xmlNodePtr CombinedRoot = xmlDocGetRootElement(CombinedDoc);
std::vector<xmlNsPtr> RequiredPrefixes;
checkAndStripPrefixes(CombinedRoot, RequiredPrefixes);
- std::unique_ptr<xmlDoc> OutputDoc(xmlNewDoc((const unsigned char *)"1.0"));
+ std::unique_ptr<xmlDoc, XmlDeleter> OutputDoc(
+ xmlNewDoc((const unsigned char *)"1.0"));
xmlDocSetRootElement(OutputDoc.get(), CombinedRoot);
+ assert(0 == xmlDocGetRootElement(CombinedDoc));
+
xmlKeepBlanksDefault(0);
- xmlDocDumpFormatMemoryEnc(OutputDoc.get(), &XmlBuff, &BufferSize, "UTF-8",
- 1);
+ xmlChar *Buff = nullptr;
+ xmlDocDumpFormatMemoryEnc(OutputDoc.get(), &Buff, &BufferSize, "UTF-8", 1);
+ Buffer.reset(Buff);
}
- if (BufferSize == 0)
- return nullptr;
- return MemoryBuffer::getMemBuffer(
- StringRef(FROM_XML_CHAR(XmlBuff), (size_t)BufferSize));
+
+ return BufferSize ? MemoryBuffer::getMemBuffer(StringRef(
+ FROM_XML_CHAR(Buffer.get()), (size_t)BufferSize))
+ : nullptr;
}
#else
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37321.113562.patch
Type: text/x-patch
Size: 2915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170901/cee7f98f/attachment.bin>
More information about the llvm-commits
mailing list