summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/YAMLTraits.cpp
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2013-01-08 21:04:44 +0000
committerNick Kledzik <kledzik@apple.com>2013-01-08 21:04:44 +0000
commit0dcef84b13cecf619fb255dd81b1ccbf2b654250 (patch)
tree1e2b2f8bbf6f017f3b4a7c58d0bcc3e4dea70706 /llvm/lib/Support/YAMLTraits.cpp
parentc2453dd8f58b57766e4e53f179f970d4a2fb9a2c (diff)
downloadbcm5719-llvm-0dcef84b13cecf619fb255dd81b1ccbf2b654250.tar.gz
bcm5719-llvm-0dcef84b13cecf619fb255dd81b1ccbf2b654250.zip
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. llvm-svn: 171896
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp41
1 files changed, 32 insertions, 9 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index ef3948dfd3a..9da2aa7c841 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -40,11 +40,17 @@ void IO::setContext(void *Context) {
// Input
//===----------------------------------------------------------------------===//
-Input::Input(StringRef InputContent, void *Ctxt) : IO(Ctxt), CurrentNode(NULL) {
- Strm = new Stream(InputContent, SrcMgr);
+Input::Input(StringRef InputContent, void *Ctxt)
+ : IO(Ctxt),
+ Strm(new Stream(InputContent, SrcMgr)),
+ CurrentNode(NULL) {
DocIterator = Strm->begin();
}
+Input::~Input() {
+
+}
+
error_code Input::error() {
return EC;
}
@@ -65,7 +71,8 @@ bool Input::setCurrentDocument() {
++DocIterator;
return setCurrentDocument();
}
- CurrentNode = this->createHNodes(N);
+ TopNode.reset(this->createHNodes(N));
+ CurrentNode = TopNode.get();
return true;
}
return false;
@@ -271,13 +278,13 @@ Input::HNode *Input::createHNodes(Node *N) {
if (!StringStorage.empty()) {
// Copy string to permanent storage
unsigned Len = StringStorage.size();
- char *Buf = Allocator.Allocate<char>(Len);
+ char *Buf = StringAllocator.Allocate<char>(Len);
memcpy(Buf, &StringStorage[0], Len);
KeyStr = StringRef(Buf, Len);
}
- return new (Allocator) ScalarHNode(N, KeyStr);
+ return new ScalarHNode(N, KeyStr);
} else if (SequenceNode *SQ = dyn_cast<SequenceNode>(N)) {
- SequenceHNode *SQHNode = new (Allocator) SequenceHNode(N);
+ SequenceHNode *SQHNode = new SequenceHNode(N);
for (SequenceNode::iterator i = SQ->begin(), End = SQ->end(); i != End;
++i) {
HNode *Entry = this->createHNodes(i);
@@ -287,7 +294,7 @@ Input::HNode *Input::createHNodes(Node *N) {
}
return SQHNode;
} else if (MappingNode *Map = dyn_cast<MappingNode>(N)) {
- MapHNode *mapHNode = new (Allocator) MapHNode(N);
+ MapHNode *mapHNode = new MapHNode(N);
for (MappingNode::iterator i = Map->begin(), End = Map->end(); i != End;
++i) {
ScalarNode *KeyScalar = dyn_cast<ScalarNode>(i->getKey());
@@ -296,7 +303,7 @@ Input::HNode *Input::createHNodes(Node *N) {
if (!StringStorage.empty()) {
// Copy string to permanent storage
unsigned Len = StringStorage.size();
- char *Buf = Allocator.Allocate<char>(Len);
+ char *Buf = StringAllocator.Allocate<char>(Len);
memcpy(Buf, &StringStorage[0], Len);
KeyStr = StringRef(Buf, Len);
}
@@ -307,7 +314,7 @@ Input::HNode *Input::createHNodes(Node *N) {
}
return mapHNode;
} else if (isa<NullNode>(N)) {
- return new (Allocator) EmptyHNode(N);
+ return new EmptyHNode(N);
} else {
setError(N, "unknown node kind");
return NULL;
@@ -327,6 +334,22 @@ void Input::setError(const Twine &Message) {
this->setError(CurrentNode, Message);
}
+Input::MapHNode::~MapHNode() {
+ for (MapHNode::NameToNode::iterator i = Mapping.begin(), End = Mapping.end();
+ i != End; ++i) {
+ delete i->second;
+ }
+}
+
+Input::SequenceHNode::~SequenceHNode() {
+ for (std::vector<HNode*>::iterator i = Entries.begin(), End = Entries.end();
+ i != End; ++i) {
+ delete *i;
+ }
+}
+
+
+
//===----------------------------------------------------------------------===//
// Output
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud