From cd10743907df223b7dd5b3a3deb20fde758b8ed7 Mon Sep 17 00:00:00 2001
From: westcott <westcott>
Date: Thu, 19 Mar 2009 17:04:49 +0000
Subject: [PATCH] fixed memory leak of groupmap in reads

---
 errorchecking.cpp    | 4 ++--
 fullmatrix.cpp       | 4 ++--
 libshuffcommand.cpp  | 5 +++++
 parselistcommand.cpp | 1 +
 progress.cpp         | 4 ++--
 readdistcommand.cpp  | 1 +
 readmatrix.cpp       | 6 +++---
 readotucommand.cpp   | 2 ++
 8 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/errorchecking.cpp b/errorchecking.cpp
index 5f587a9..9a08462 100644
--- a/errorchecking.cpp
+++ b/errorchecking.cpp
@@ -171,8 +171,8 @@ bool ErrorCheck::checkInput(string input) {
 				errorFree = false;
 		} 
 		
-		if ((commandName == "libshuff") && (globaldata->gMatrix == NULL)) {
-			 cout << "You must read in a matrix before you use the libshuff command. " << endl; return false; 
+		if ((commandName == "libshuff") && ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL))) {
+			 cout << "You must read in a matrix and groupfile before you use the libshuff command. " << endl; return false; 
 		}
 		
 		if (commandName == "parsimony") {
diff --git a/fullmatrix.cpp b/fullmatrix.cpp
index 8eb4813..f4acd78 100644
--- a/fullmatrix.cpp
+++ b/fullmatrix.cpp
@@ -75,7 +75,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
 	try {
 	
 		Progress* reading;
-		reading = new Progress("Reading matrix:    ", numSeqs * numSeqs);
+		reading = new Progress("Reading matrix:     ", numSeqs * numSeqs);
 		
 		int count = 0;
 		
@@ -114,7 +114,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
 void FullMatrix::readLTMatrix(ifstream& filehandle) {
 	try {
 		Progress* reading;
-		reading = new Progress("Reading matrix:    ", numSeqs * (numSeqs - 1) / 2);
+		reading = new Progress("Reading matrix:     ", numSeqs * (numSeqs - 1) / 2);
 		
 		int count = 0;
 		float distance;
diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp
index 2ed7ee5..9ab9108 100644
--- a/libshuffcommand.cpp
+++ b/libshuffcommand.cpp
@@ -72,6 +72,8 @@ int LibShuffCommand::execute(){
 	try {
 		//deltaValues[0] = scores for the difference between AA and AB.
 		//cValues[0][0][0] = AA at distance 0.0, cValues[0][0][1] = AB at distance 0.0, cValues[0][0][2] = AC at distance 0.0, cValues[0][1][0] = BA at distance 0.0, cValues[0][1][1] = BB...
+		Progress* reading;
+		reading = new Progress("Comparing to random:", iters);
 		
 		sumDelta.resize(numComp-numGroups, 0.0);
 		
@@ -153,6 +155,7 @@ int LibShuffCommand::execute(){
 			}
 //cout << "iter " << m << endl;
 			//clear out old Values
+			reading->update(m);
 			cValues.clear();
 			
 //cout << "random sum delta for iter " << m << endl;
@@ -163,6 +166,8 @@ int LibShuffCommand::execute(){
 
 		}
 		
+		reading->finish();
+		delete reading;
 				
 		/**********************************************************/
 		//find the signifigance of the user matrix' sumdelta values
diff --git a/parselistcommand.cpp b/parselistcommand.cpp
index d9925ad..73fb565 100644
--- a/parselistcommand.cpp
+++ b/parselistcommand.cpp
@@ -135,6 +135,7 @@ int ParseListCommand::execute(){
 			}
 			
 			//set groupmap for .shared commands
+			if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
 			globaldata->gGroupmap = groupMap; 
 			
 			return 0;
diff --git a/progress.cpp b/progress.cpp
index eec8f09..9f3327f 100644
--- a/progress.cpp
+++ b/progress.cpp
@@ -20,7 +20,7 @@ const char marker = '|';
 
 Progress::Progress(string job, int end){
 	try {
-		cout << "*******************#****#****#****#****#****#****#****#****#****#****#\n";
+		cout << "********************#****#****#****#****#****#****#****#****#****#****#\n";
 		cout << job << marker;
 		cout.flush();
 	
@@ -72,7 +72,7 @@ void Progress::finish(){
 	
 	
 		cout << endl;
-		cout << "**********************************************************************\n";
+		cout << "***********************************************************************\n";
 		cout.flush();
 	}
 	catch(exception& e) {
diff --git a/readdistcommand.cpp b/readdistcommand.cpp
index a9d7721..6d38f4e 100644
--- a/readdistcommand.cpp
+++ b/readdistcommand.cpp
@@ -21,6 +21,7 @@ ReadDistCommand::ReadDistCommand(){
 		else if (format == "matrix") { 
 				groupMap = new GroupMap(globaldata->getGroupFile());
 				groupMap->readMap();
+				if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
 				globaldata->gGroupmap = groupMap;
 		}
 		
diff --git a/readmatrix.cpp b/readmatrix.cpp
index 2d98124..9a98d5c 100644
--- a/readmatrix.cpp
+++ b/readmatrix.cpp
@@ -69,7 +69,7 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
 	
 			if(square == 0){
 
-				reading = new Progress("Reading matrix:    ", nseqs * (nseqs - 1) / 2);
+				reading = new Progress("Reading matrix:     ", nseqs * (nseqs - 1) / 2);
 		
 				int	index = 0;
 		
@@ -111,7 +111,7 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){
 			}
 			else{
 
-				reading = new Progress("Reading matrix:    ", nseqs * nseqs);
+				reading = new Progress("Reading matrix:     ", nseqs * nseqs);
 			
 				int index = nseqs;
 		
@@ -202,7 +202,7 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){
 
 			list = new ListVector(nameMap->getListVector());
 		
-			Progress* reading = new Progress("Reading matrix:    ", nseqs * nseqs);
+			Progress* reading = new Progress("Reading matrix:     ", nseqs * nseqs);
 	
 			int lt = 1;
 			int refRow = 0;	//we'll keep track of one cell - Cell(refRow,refCol) - and see if it's transpose
diff --git a/readotucommand.cpp b/readotucommand.cpp
index eeb8cd6..2a0d33f 100644
--- a/readotucommand.cpp
+++ b/readotucommand.cpp
@@ -43,6 +43,8 @@ int ReadOtuCommand::execute(){
 		read->read(&*globaldata); 
 		if (globaldata->getFormat() == "shared") {
 			groupMap->readMap();
+			
+			if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
 			globaldata->gGroupmap = groupMap;
 		
 			shared = new SharedCommand();
-- 
2.39.5