OSDN Git Service

[TextAPI] Fix a memory leak in the TBD reader.
authorJuergen Ributzka <juergen@ributzka.de>
Thu, 29 Nov 2018 06:16:33 +0000 (06:16 +0000)
committerJuergen Ributzka <juergen@ributzka.de>
Thu, 29 Nov 2018 06:16:33 +0000 (06:16 +0000)
This fixes an issue where we were leaking the YAML document if there was a
parsing error.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347837 91177308-0d34-0410-b5e6-96231b3b80d8

lib/TextAPI/MachO/TextStub.cpp

index 630663d..be4d69c 100644 (file)
@@ -634,11 +634,13 @@ TextAPIReader::get(std::unique_ptr<MemoryBuffer> InputBuffer) {
   std::vector<const InterfaceFile *> Files;
   YAMLIn >> Files;
 
+  auto File = std::unique_ptr<InterfaceFile>(
+      const_cast<InterfaceFile *>(Files.front()));
+
   if (YAMLIn.error())
     return make_error<StringError>(Ctx.ErrorMessage, YAMLIn.error());
 
-  auto *File = const_cast<InterfaceFile *>(Files.front());
-  return std::unique_ptr<InterfaceFile>(File);
+  return File;
 }
 
 Error TextAPIWriter::writeToStream(raw_ostream &OS, const InterfaceFile &File) {