]> git.donarmstrong.com Git - mothur.git/commitdiff
fixed memory leak globaldata container structures, gTreemap, ginput, gorder, gSharedL...
authorwestcott <westcott>
Thu, 19 Mar 2009 17:48:18 +0000 (17:48 +0000)
committerwestcott <westcott>
Thu, 19 Mar 2009 17:48:18 +0000 (17:48 +0000)
parsimonycommand.cpp
readdistcommand.cpp
readmatrix.cpp
readtreecommand.cpp

index e7d64e5201a5f1e29c3fce9c85d0622793138837..421cac363feb5380787c8a52fe4e5ad2fe60c9f9 100644 (file)
@@ -166,7 +166,11 @@ int ParsimonyCommand::execute() {
                if (randomtree == "") { printUSummaryFile(); }
                
                //reset globaldata's treemap if you just did random distrib
                if (randomtree == "") { printUSummaryFile(); }
                
                //reset globaldata's treemap if you just did random distrib
-               if (randomtree != "") { globaldata->gTreemap = savetmap; }
+               if (randomtree != "") {
+                       //memory leak prevention
+                       if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap;  }
+                       globaldata->gTreemap = savetmap;
+               }
                
                //reset randomTree parameter to ""
                globaldata->setRandomTree("");
                
                //reset randomTree parameter to ""
                globaldata->setRandomTree("");
@@ -293,6 +297,8 @@ void ParsimonyCommand::getUserInput() {
                getline(cin, s);
                
                //save tmap for later
                getline(cin, s);
                
                //save tmap for later
+               //memory leak prevention
+               if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap;  }
                globaldata->gTreemap = tmap;
                
        }
                globaldata->gTreemap = tmap;
                
        }
index 6d38f4e4d55cde380570dd53aaa847f96600550f..9db835a2fb5ffe492b145e64213191fa8d901baa 100644 (file)
@@ -70,6 +70,8 @@ int ReadDistCommand::execute(){
                        ifstream in;
                        openInputFile(filename, in);
                        matrix = new FullMatrix(in); //reads the matrix file
                        ifstream in;
                        openInputFile(filename, in);
                        matrix = new FullMatrix(in); //reads the matrix file
+                       //memory leak prevention
+                       if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix;  }
                        globaldata->gMatrix = matrix; //save matrix for coverage commands
                }else {
                        read->read(nameMap);
                        globaldata->gMatrix = matrix; //save matrix for coverage commands
                }else {
                        read->read(nameMap);
index 9a98d5c393390104abfacffde8ceae948d277ac3..b2a2ffac57ef83c9449172baa62856d78deca4a2 100644 (file)
@@ -346,15 +346,22 @@ void ReadPhilFile::read(GlobalData* globaldata){
                }else {//there is an orderfile
                        input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat());
                }
                }else {//there is an orderfile
                        input = new InputData(philFile, globaldata->getOrderFile(), globaldata->getFormat());
                }
+               
+               //memory leak prevention
+               if (globaldata->ginput != NULL) { delete globaldata->ginput;  }
                globaldata->ginput = input;     //saving to be used by collector and rarefact commands.
                
                if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary.
                        order = input->getOrderVector();
                globaldata->ginput = input;     //saving to be used by collector and rarefact commands.
                
                if ((globaldata->getFormat() == "list") || (globaldata->getFormat() == "rabund") || (globaldata->getFormat() == "sabund")) {//you are reading a list, rabund or sabund file for collect, rarefaction or summary.
                        order = input->getOrderVector();
+                       //memory leak prevention
+                       if (globaldata->gorder != NULL) { delete globaldata->gorder;  }
                        globaldata->gorder = order;     //saving to be used by collect and rarefact commands.
                        sabund = inputSabund->getSAbundVector(); 
                        globaldata->sabund = sabund; //saving to be used by summary command.
                }else if (globaldata->getFormat() == "shared") {
                        SharedList = input->getSharedListVector(); //you are reading for collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands.
                        globaldata->gorder = order;     //saving to be used by collect and rarefact commands.
                        sabund = inputSabund->getSAbundVector(); 
                        globaldata->sabund = sabund; //saving to be used by summary command.
                }else if (globaldata->getFormat() == "shared") {
                        SharedList = input->getSharedListVector(); //you are reading for collect.shared, rarefaction.shared, summary.shared, parselist command, or shared commands.
+                       //memory leak prevention
+                       if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList;  }
                        globaldata->gSharedList = SharedList;
                }
        }
                        globaldata->gSharedList = SharedList;
                }
        }
index 405de84daef015d5edb37110ab35f0a2c98bbbb3..8124d53415bda6035a3f6686d8ebc50a3ecb1419 100644 (file)
@@ -18,6 +18,9 @@ ReadTreeCommand::ReadTreeCommand(){
                //read in group map info.
                treeMap = new TreeMap(globaldata->getGroupFile());
                treeMap->readMap();
                //read in group map info.
                treeMap = new TreeMap(globaldata->getGroupFile());
                treeMap->readMap();
+               
+               //memory leak prevention
+               if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap;  }
                globaldata->gTreemap = treeMap;
 
                read = new ReadNewickTree(filename);
                globaldata->gTreemap = treeMap;
 
                read = new ReadNewickTree(filename);