<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 18, 2015 at 2:11 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Mon May 18 16:11:27 2015<br>
New Revision: 237614<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=237614&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=237614&view=rev</a><br>
Log:<br>
[YAML] Plug a memory leak<br>
<br>
The destructor of BlockScalarNode is never called. Store the contained<br>
string in BumpPtrAllocated memory instead.<br></blockquote><div><br>Reckon we could put a static_assert in BumpPtrAllocator that checks that objects allocated with it have trivial destruction? I suppose that'd work in SpecificBumpPtrAllocator - but maybe we could template the allocate operation of the non-specificBumpPtrAllocator to catch them there too... <br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified:<br>
    llvm/trunk/include/llvm/Support/YAMLParser.h<br>
    llvm/trunk/lib/Support/YAMLParser.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/Support/YAMLParser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLParser.h?rev=237614&r1=237613&r2=237614&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLParser.h?rev=237614&r1=237613&r2=237614&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/YAMLParser.h (original)<br>
+++ llvm/trunk/include/llvm/Support/YAMLParser.h Mon May 18 16:11:27 2015<br>
@@ -235,8 +235,8 @@ class BlockScalarNode : public Node {<br>
<br>
 public:<br>
   BlockScalarNode(std::unique_ptr<Document> &D, StringRef Anchor, StringRef Tag,<br>
-                  std::string &Value, StringRef RawVal)<br>
-      : Node(NK_BlockScalar, D, Anchor, Tag), Value(std::move(Value)) {<br>
+                  StringRef Value, StringRef RawVal)<br>
+      : Node(NK_BlockScalar, D, Anchor, Tag), Value(Value) {<br>
     SMLoc Start = SMLoc::getFromPointer(RawVal.begin());<br>
     SMLoc End = SMLoc::getFromPointer(RawVal.end());<br>
     SourceRange = SMRange(Start, End);<br>
@@ -250,7 +250,7 @@ public:<br>
   }<br>
<br>
 private:<br>
-  std::string Value;<br>
+  StringRef Value;<br>
 };<br>
<br>
 /// \brief A key and value pair. While not technically a Node under the YAML<br>
<br>
Modified: llvm/trunk/lib/Support/YAMLParser.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLParser.cpp?rev=237614&r1=237613&r2=237614&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/YAMLParser.cpp?rev=237614&r1=237613&r2=237614&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/YAMLParser.cpp (original)<br>
+++ llvm/trunk/lib/Support/YAMLParser.cpp Mon May 18 16:11:27 2015<br>
@@ -2377,11 +2377,13 @@ parse_property:<br>
                 , AnchorInfo.Range.substr(1)<br>
                 , TagInfo.Range<br>
                 , T.Range);<br>
-  case Token::TK_BlockScalar:<br>
+  case Token::TK_BlockScalar: {<br>
     getNext();<br>
+    StringRef StrCopy = StringRef(T.Value).copy(NodeAllocator);<br>
     return new (NodeAllocator)<br>
         BlockScalarNode(stream.CurrentDoc, AnchorInfo.Range.substr(1),<br>
-                        TagInfo.Range, T.Value, T.Range);<br>
+                        TagInfo.Range, StrCopy, T.Range);<br>
+  }<br>
   case Token::TK_Key:<br>
     // Don't eat the TK_Key, KeyValueNode expects it.<br>
     return new (NodeAllocator)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>