From 5498499139c6a309e9c908befc304148975d61fe Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Mon, 16 Jun 2014 23:27:41 +0200
Subject: [PATCH] fix all memory leaks

---
 alib2/src/alphabet/SymbolFromStringParser.cpp | 9 ++++++---
 alib2/src/label/LabelFromStringParser.cpp     | 1 +
 alib2/src/regexp/RegExpFromStringParser.cpp   | 9 ++++++---
 alib2/src/string/StringFromStringParser.cpp   | 4 +++-
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/alib2/src/alphabet/SymbolFromStringParser.cpp b/alib2/src/alphabet/SymbolFromStringParser.cpp
index 718b472f82..cf1cd464da 100644
--- a/alib2/src/alphabet/SymbolFromStringParser.cpp
+++ b/alib2/src/alphabet/SymbolFromStringParser.cpp
@@ -16,9 +16,11 @@ Symbol* SymbolFromStringParser::parse() {
 		return new Symbol(BlankSymbol());
 	case SymbolFromStringLexer::TokenType::ERROR: {
 		label::Label* label = m_LabelParser.parse();
-		if(label != NULL)
-			return new Symbol(LabeledSymbol(*label));
-		else
+		if(label != NULL) {
+			Symbol* res = new Symbol(LabeledSymbol(std::move(*label)));
+			delete label;
+			return res;
+		} else
 			return NULL;
 	}
 	case SymbolFromStringLexer::TokenType::TEOF:
@@ -36,6 +38,7 @@ Symbol SymbolFromStringParser::parseSymbol() {
 		delete symbol;
 		return std::move(res);
 	} else {
+		delete symbol;
 		throw alib::AlibException();
 	}
 }
diff --git a/alib2/src/label/LabelFromStringParser.cpp b/alib2/src/label/LabelFromStringParser.cpp
index 4d69086ffe..d172aef6bc 100644
--- a/alib2/src/label/LabelFromStringParser.cpp
+++ b/alib2/src/label/LabelFromStringParser.cpp
@@ -35,6 +35,7 @@ Label LabelFromStringParser::parseLabel() {
 		delete label;
 		return std::move(res);
 	} else {
+		delete label;
 		throw alib::AlibException();
 	}
 }
diff --git a/alib2/src/regexp/RegExpFromStringParser.cpp b/alib2/src/regexp/RegExpFromStringParser.cpp
index a3fefdd1aa..296bfb5a43 100644
--- a/alib2/src/regexp/RegExpFromStringParser.cpp
+++ b/alib2/src/regexp/RegExpFromStringParser.cpp
@@ -29,6 +29,7 @@ RegExp RegExpFromStringParser::parseRegexp() {
 		delete regexp;
 		return std::move(res);
 	} else {
+		delete regexp;
 		throw alib::AlibException();
 	}
 }
@@ -144,9 +145,11 @@ RegExpElement* RegExpFromStringParser::factor() {
 		return this->star(new RegExpEmpty());
 	} else if(token.type == RegExpFromStringLexer::TokenType::ERROR) {
 		alphabet::Symbol* symbol = m_SymbolParser.parse();
-		if(symbol != NULL)
-			return this->star(new RegExpSymbol(*symbol));
-		else
+		if(symbol != NULL) {
+			RegExpSymbol* res = new RegExpSymbol(std::move(*symbol));
+			delete symbol;
+			return this->star(res);
+		} else
 			return NULL;
 	} else {
 		return NULL;
diff --git a/alib2/src/string/StringFromStringParser.cpp b/alib2/src/string/StringFromStringParser.cpp
index b7393a8264..d93d79e0e8 100644
--- a/alib2/src/string/StringFromStringParser.cpp
+++ b/alib2/src/string/StringFromStringParser.cpp
@@ -47,6 +47,7 @@ String StringFromStringParser::parseString() {
 		delete string;
 		return std::move(res);
 	} else {
+		delete string;
 		throw alib::AlibException();
 	}
 }
@@ -58,7 +59,8 @@ std::vector<alphabet::Symbol> StringFromStringParser::parseContent() {
 		symbol = m_SymbolParser.parse();
 		if(symbol == NULL)
 			return data;
-		data.push_back(*symbol);
+		data.push_back(std::move(*symbol));
+		delete symbol;
 	} while(true);
 }
 
-- 
GitLab