diff options
author | Nick Kledzik <kledzik@apple.com> | 2013-01-08 21:04:44 +0000 |
---|---|---|
committer | Nick Kledzik <kledzik@apple.com> | 2013-01-08 21:04:44 +0000 |
commit | 02fa38344c1cf1f27d59da5c3358d19bbb752f01 (patch) | |
tree | 16a6310e5d06ff09c159b9ed477401c92a618031 /include/llvm/Support/YAMLTraits.h | |
parent | a67352d4012b9db3c0c06cf962c0e561054753c3 (diff) | |
download | llvm-02fa38344c1cf1f27d59da5c3358d19bbb752f01.tar.gz llvm-02fa38344c1cf1f27d59da5c3358d19bbb752f01.tar.bz2 llvm-02fa38344c1cf1f27d59da5c3358d19bbb752f01.tar.xz |
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
Diffstat (limited to 'include/llvm/Support/YAMLTraits.h')
-rw-r--r-- | include/llvm/Support/YAMLTraits.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/include/llvm/Support/YAMLTraits.h b/include/llvm/Support/YAMLTraits.h index 821333bf2f..186228624a 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<llvm::yaml::Stream> Strm; + OwningPtr<HNode> TopNode; llvm::error_code EC; - llvm::BumpPtrAllocator Allocator; + llvm::BumpPtrAllocator StringAllocator; llvm::yaml::document_iterator DocIterator; std::vector<bool> BitValuesUsed; HNode *CurrentNode; |