[lld] r224191 - Make YAML files own MemoryBuffer.

Rui Ueyama ruiu at google.com
Sat Dec 13 00:59:50 PST 2014


Author: ruiu
Date: Sat Dec 13 02:59:50 2014
New Revision: 224191

URL: http://llvm.org/viewvc/llvm-project?rev=224191&view=rev
Log:
Make YAML files own MemoryBuffer.

YAML files have references such as StringRef to the underlying
MemoryBuffer, so we shouldn't deallocate the buffer.

Modified:
    lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp

Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=224191&r1=224190&r2=224191&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Sat Dec 13 02:59:50 2014
@@ -1327,11 +1327,6 @@ public:
   std::error_code
   parseFile(std::unique_ptr<MemoryBuffer> mb, const class Registry &,
             std::vector<std::unique_ptr<File>> &result) const override {
-    // Note: we do not store the unique pointer to the MemoryBuffer,
-    // so the buffer will be deallocated at end of this function.
-    // That's OK since the YAML file contents are parsed and consumed
-    // in this function.
-
     // Create YAML Input Reader.
     YamlContext yamlContext;
     yamlContext._registry = &_registry;
@@ -1346,10 +1341,12 @@ public:
     if (yin.error())
       return make_error_code(lld::YamlReaderError::illegal_value);
 
+    std::shared_ptr<MemoryBuffer> smb(mb.release());
     for (const File *file : createdFiles) {
       // Note: parseFile() should return vector of *const* File
       File *f = const_cast<File *>(file);
       f->setLastError(std::error_code());
+      f->setSharedMemoryBuffer(smb);
       result.emplace_back(f);
     }
     return make_error_code(lld::YamlReaderError::success);





More information about the llvm-commits mailing list