From: westcott Date: Thu, 19 Mar 2009 17:48:18 +0000 (+0000) Subject: fixed memory leak globaldata container structures, gTreemap, ginput, gorder, gSharedL... X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9e07ea7484097a73e0e9ce3e379c12bfa0a4e55d;p=mothur.git fixed memory leak globaldata container structures, gTreemap, ginput, gorder, gSharedList, gMatrix. --- diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index e7d64e5..421cac3 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -166,7 +166,11 @@ int ParsimonyCommand::execute() { 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(""); @@ -293,6 +297,8 @@ void ParsimonyCommand::getUserInput() { getline(cin, s); //save tmap for later + //memory leak prevention + if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } globaldata->gTreemap = tmap; } diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 6d38f4e..9db835a 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -70,6 +70,8 @@ int ReadDistCommand::execute(){ 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); diff --git a/readmatrix.cpp b/readmatrix.cpp index 9a98d5c..b2a2ffa 100644 --- a/readmatrix.cpp +++ b/readmatrix.cpp @@ -346,15 +346,22 @@ void ReadPhilFile::read(GlobalData* globaldata){ }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(); + //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. + //memory leak prevention + if (globaldata->gSharedList != NULL) { delete globaldata->gSharedList; } globaldata->gSharedList = SharedList; } } diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 405de84..8124d53 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -18,6 +18,9 @@ ReadTreeCommand::ReadTreeCommand(){ //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);