[YAML] Plug a memory leak

The destructor of BlockScalarNode is never called. Store the contained
string in BumpPtrAllocated memory instead.

llvm-svn: 237614
This commit is contained in:
Benjamin Kramer 2015-05-18 21:11:27 +00:00
parent 4662acc8ae
commit 624b011af1
2 changed files with 7 additions and 5 deletions

View File

@ -235,8 +235,8 @@ class BlockScalarNode : public Node {
public:
BlockScalarNode(std::unique_ptr<Document> &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

View File

@ -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)