From 4daed5ebe3e8eae184a96055974ac15a3c55507f Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sun, 15 Apr 2012 00:26:12 +0200 Subject: Removed all memory leaks detected by valgrind --- tree.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tree.cpp') diff --git a/tree.cpp b/tree.cpp index 0ef3a39..29dbab1 100644 --- a/tree.cpp +++ b/tree.cpp @@ -69,11 +69,20 @@ Tree::Tree() this->nodeCollection = new vector(); } +Tree::~Tree() +{ + for ( vector::iterator it = this->nodeCollection->begin(); it != this->nodeCollection->end(); it++ ) + { + delete *it; + } + + delete this->nodeCollection; +} + Node* Tree::addOperand(Node **place, double value) { OperandNode *newNode = new OperandNode(); - newNode = new OperandNode(); newNode->value = value; this->nodeCollection->push_back( newNode ); @@ -89,7 +98,6 @@ Node* Tree::addOperator(Node **place, char oper) { OperatorNode *newNode = new OperatorNode(); - newNode = new OperatorNode(); newNode->function = oper; this->nodeCollection->push_back( newNode ); -- cgit v1.2.3