From 825a528bbe85911df5b0b0fe87566dca96e7e59f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 18 May 2015 21:11:27 +0000 Subject: [PATCH] [YAML] Plug a memory leak The destructor of BlockScalarNode is never called. Store the contained string in BumpPtrAllocated memory instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237614 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/YAMLParser.h | 6 +++--- lib/Support/YAMLParser.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/llvm/Support/YAMLParser.h b/include/llvm/Support/YAMLParser.h index f0b6113e836..5158b591e0f 100644 --- a/include/llvm/Support/YAMLParser.h +++ b/include/llvm/Support/YAMLParser.h @@ -235,8 +235,8 @@ class BlockScalarNode : public Node { public: BlockScalarNode(std::unique_ptr &D, StringRef Anchor, StringRef Tag, - std::string &Value, StringRef RawVal) - : Node(NK_BlockScalar, D, Anchor, Tag), Value(std::move(Value)) { + StringRef Value, StringRef RawVal) + : Node(NK_BlockScalar, D, Anchor, Tag), Value(Value) { SMLoc Start = SMLoc::getFromPointer(RawVal.begin()); SMLoc End = SMLoc::getFromPointer(RawVal.end()); SourceRange = SMRange(Start, End); @@ -250,7 +250,7 @@ public: } private: - std::string Value; + StringRef Value; }; /// \brief A key and value pair. While not technically a Node under the YAML diff --git a/lib/Support/YAMLParser.cpp b/lib/Support/YAMLParser.cpp index 162a22bd910..41d446744fe 100644 --- a/lib/Support/YAMLParser.cpp +++ b/lib/Support/YAMLParser.cpp @@ -2377,11 +2377,13 @@ parse_property: , AnchorInfo.Range.substr(1) , TagInfo.Range , T.Range); - case Token::TK_BlockScalar: + case Token::TK_BlockScalar: { getNext(); + StringRef StrCopy = StringRef(T.Value).copy(NodeAllocator); return new (NodeAllocator) BlockScalarNode(stream.CurrentDoc, AnchorInfo.Range.substr(1), - TagInfo.Range, T.Value, T.Range); + TagInfo.Range, StrCopy, T.Range); + } case Token::TK_Key: // Don't eat the TK_Key, KeyValueNode expects it. return new (NodeAllocator) -- 2.34.1