Commit 4b5b5ef0 authored by kraus's avatar kraus
Browse files

fixing memory leaks

parent 695cf3a9
......@@ -61,8 +61,7 @@ void Inform::setup(const char *myname, int pnode) {
PrintNode = pnode;
if ( myname != 0 ) {
Name = new char[strlen(myname) + 1];
strcpy(Name, myname);
Name = strcpy(new char[strlen(myname) + 1], myname);
} else {
Name = 0;
}
......
......@@ -641,7 +641,6 @@ IpplInfo::~IpplInfo() {
// dbgmsg << " Deleting comm object, since now NumCreated = ";
// dbgmsg << NumCreated << endl;
delete Comm;
Comm = new Communicate();
NeedDeleteComm = false;
}
......@@ -1091,6 +1090,10 @@ void IpplInfo::stash() {
obj.Comm = Comm;
obj.Stats = Stats;
obj.Info = Info;
obj.Warn = Warn;
obj.Error = Error;
obj.Debug = Debug;
obj.deferGuardCellFills = deferGuardCellFills;
obj.noFieldCompression = noFieldCompression;
obj.offsetStorage = offsetStorage;
......@@ -1120,8 +1123,13 @@ void IpplInfo::stash() {
stashedStaticMembers.push(obj);
Comm = new Communicate();
Stats = new IpplStats();
Comm = 0;
Stats = 0;
// can't set Info and Warn to zero since
// IpplInfoWrapper requires valid objects
Error = 0;
Debug = 0;
deferGuardCellFills = false;
noFieldCompression = false;
offsetStorage = false;
......@@ -1153,14 +1161,22 @@ void IpplInfo::pop() {
stashedStaticMembers.pop();
// Delete the communications object, if necessary, to shut down parallel
// environment
delete Comm;
// Comm is deleted in destructor
delete [] MyArgv;
delete [] SMPIDList;
delete [] SMPNodeList;
delete Info;
delete Warn;
delete Error;
delete Debug;
delete Stats;
Comm = obj.Comm;
Stats = obj.Stats;
Info = obj.Info;
Warn = obj.Warn;
Error = obj.Error;
Debug = obj.Debug;
deferGuardCellFills = obj.deferGuardCellFills;
noFieldCompression = obj.noFieldCompression;
offsetStorage = obj.offsetStorage;
......@@ -1217,4 +1233,4 @@ void __C_runtime_error ( int trap_code, char *name, int line_no, ... ) {
* $RCSfile: IpplInfo.cpp,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: IpplInfo.cpp,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
***************************************************************************/
\ No newline at end of file
......@@ -5,6 +5,7 @@
class Communicate;
class IpplStats;
class Inform;
//DKS include
#ifdef IPPL_DKS
class DKSOPAL;
......@@ -26,6 +27,11 @@ public:
// the statistics collection object
IpplStats *Stats;
Inform *Info;
Inform *Warn;
Inform *Error;
Inform *Debug;
#ifdef IPPL_DKS
DKSOPAL *DKS;
#endif
......@@ -110,4 +116,4 @@ public:
};
#endif
#endif
\ No newline at end of file
......@@ -899,21 +899,18 @@ void PartBunchBase<T, Dim>::get_bounds(Vector_t &rmin, Vector_t &rmax) {
this->getLocalBounds(rmin, rmax);
double min[Dim];
double max[Dim];
double min[2*Dim];
for (unsigned int i = 0; i < Dim; ++i) {
min[i] = rmin[i];
max[i] = rmax[i];
min[2*i] = rmin[i];
min[2*i + 1] = -rmax[i];
}
//FIXME use a min-max function
allreduce(&min[0], Dim, std::less<double>());
allreduce(&max[0], Dim, std::greater<double>());
allreduce(min, 2*Dim, std::less<double>());
for (unsigned int i = 0; i < Dim; ++i) {
rmin[i] = min[i];
rmax[i] = max[i];
rmin[i] = min[2*i];
rmax[i] = -min[2*i + 1];
}
}
......@@ -1310,7 +1307,7 @@ void PartBunchBase<T, Dim>::calcBeamParameters() {
for(size_t i = 0; i < locNp; i++)
gamma += sqrt(1.0 + dot(P[i], P[i]));
allreduce(gamma, 1, std::plus<double>());
allreduce(&gamma, 1, std::plus<double>());
gamma /= N;
calcEMean();
......@@ -1960,7 +1957,7 @@ size_t PartBunchBase<T, Dim>::calcMoments() {
}
}
allreduce(&loc_moments[0], loc_moments.size(), std::plus<double>());
allreduce(loc_moments.data(), loc_moments.size(), std::plus<double>());
// copy to member variables
for (unsigned int i = 0; i< 2 * Dim; ++i)
......@@ -2265,7 +2262,7 @@ FMatrix<double, 2 * Dim, 2 * Dim> PartBunchBase<T, Dim>::getSigmaMatrix() {
rpmean(2*i)= rmean_m(i);
rpmean((2*i)+1)= pmean_m(i);
}
FMatrix<double, 2 * Dim, 2 * Dim> sigmaMatrix;// = moments_m / N;
for (unsigned int i = 0; i < 2 * Dim; i++) {
for (unsigned int j = 0; j <= i; j++) {
......@@ -2276,4 +2273,4 @@ FMatrix<double, 2 * Dim, 2 * Dim> PartBunchBase<T, Dim>::getSigmaMatrix() {
return sigmaMatrix;
}
#endif
#endif
\ No newline at end of file
......@@ -166,6 +166,12 @@ void OpalSimulation::createSymlink_m(const std::string& path) {
target);
}
}
for(int i=0; i<count; i++) {
free(files[i]);
}
free(files);
}
void OpalSimulation::setupSimulation() {
......
......@@ -454,7 +454,6 @@ void OptimizeCmd::execute() {
Inform *origGmsg = gmsg;
gmsg = 0;
stashEnvironment();
try {
CmdArguments_t args(new CmdArguments(argv.size(), &argv[0]));
......@@ -464,7 +463,6 @@ void OptimizeCmd::execute() {
std::cout << "Exception caught: " << e.what() << std::endl;
MPI_Abort(MPI_COMM_WORLD, -100);
}
popEnvironment();
gmsg = origGmsg;
}
......@@ -549,6 +547,8 @@ void OptimizeCmd::run(const CmdArguments_t& args,
typedef SocialNetworkGraph< NoCommTopology > SolPropagationGraph_t;
boost::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD));
if (comm->isWorker())
stashEnvironment();
CrossOver crossover = this->crossoverSelection(Attributes::getString(itsAttr[CROSSOVER]));
Mutation mutation = this->mutationSelection(Attributes::getString(itsAttr[MUTATION]));
......@@ -646,4 +646,7 @@ void OptimizeCmd::run(const CmdArguments_t& args,
throw OpalException("OptimizeCmd::run",
"No such cross over and mutation combination supported.");
}
if (comm->isWorker())
popEnvironment();
}
\ No newline at end of file
......@@ -423,18 +423,21 @@ void SampleCmd::execute() {
Inform *origGmsg = gmsg;
gmsg = 0;
stashEnvironment();
try {
CmdArguments_t args(new CmdArguments(argv.size(), &argv[0]));
boost::shared_ptr<Comm_t> comm(new Comm_t(args, MPI_COMM_WORLD));
if (comm->isWorker())
stashEnvironment();
boost::scoped_ptr<pilot_t> pi(new pilot_t(args, comm, funcs, dvars, objectives, sampleMethods, storeobjstr));
if (comm->isWorker())
popEnvironment();
} catch (OptPilotException &e) {
std::cout << "Exception caught: " << e.what() << std::endl;
MPI_Abort(MPI_COMM_WORLD, -100);
}
popEnvironment();
gmsg = origGmsg;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment