From 02fa38344c1cf1f27d59da5c3358d19bbb752f01 Mon Sep 17 00:00:00 2001 From: Nick Kledzik Date: Tue, 8 Jan 2013 21:04:44 +0000 Subject: Fix memory leak in YAML I/O. Stop using BumpPtrAllocator for HNodes because they have fields (vector, map) which require HNode destructors to be run. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171896 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/YAMLTraits.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/llvm/Support/YAMLTraits.h b/include/llvm/Support/YAMLTraits.h index 821333b..1862286 100644 --- a/include/llvm/Support/YAMLTraits.h +++ b/include/llvm/Support/YAMLTraits.h @@ -685,7 +685,8 @@ class Input : public IO { public: // Construct a yaml Input object from a StringRef and optional user-data. Input(StringRef InputContent, void *Ctxt=NULL); - + ~Input(); + // Check if there was an syntax or semantic error during parsing. llvm::error_code error(); @@ -718,6 +719,7 @@ private: class HNode { public: HNode(Node *n) : _node(n) { } + virtual ~HNode() { } static inline bool classof(const HNode *) { return true; } Node *_node; @@ -726,6 +728,7 @@ private: class EmptyHNode : public HNode { public: EmptyHNode(Node *n) : HNode(n) { } + virtual ~EmptyHNode() {} static inline bool classof(const HNode *n) { return NullNode::classof(n->_node); } @@ -735,6 +738,7 @@ private: class ScalarHNode : public HNode { public: ScalarHNode(Node *n, StringRef s) : HNode(n), _value(s) { } + virtual ~ScalarHNode() { } StringRef value() const { return _value; } @@ -749,6 +753,7 @@ private: class MapHNode : public HNode { public: MapHNode(Node *n) : HNode(n) { } + virtual ~MapHNode(); static inline bool classof(const HNode *n) { return MappingNode::classof(n->_node); @@ -774,6 +779,7 @@ private: class SequenceHNode : public HNode { public: SequenceHNode(Node *n) : HNode(n) { } + virtual ~SequenceHNode(); static inline bool classof(const HNode *n) { return SequenceNode::classof(n->_node); @@ -795,10 +801,11 @@ public: void nextDocument(); private: - llvm::yaml::Stream *Strm; - llvm::SourceMgr SrcMgr; + llvm::SourceMgr SrcMgr; // must be before Strm + OwningPtr Strm; + OwningPtr TopNode; llvm::error_code EC; - llvm::BumpPtrAllocator Allocator; + llvm::BumpPtrAllocator StringAllocator; llvm::yaml::document_iterator DocIterator; std::vector BitValuesUsed; HNode *CurrentNode; -- cgit v1.1