Commit d41a7ea5 authored by Johannes Leins's avatar Johannes Leins
Browse files

removed memory leaks caused by repeated creation of pointers Instances that remained unused

parent 54c46406
Pipeline #26597 failed with stage
in 26 seconds
......@@ -504,8 +504,9 @@ CSVHandlerDisturbanceScheme::CSVHandlerDisturbanceScheme(string filename,
break;
}
Point* coord = new Point();
Point* coord;
if(emptyCoord) {
coord = new Point()
if(prob.first != tools::ConversionResult::EMPTY) {
probsByDistName[disturbanceName] = prob.second;
continue; // do not add disturbances that will be selected randomly to schemeByCoord
......
......@@ -152,24 +152,23 @@ Climate* Environment::getClimate() {
Measure* Environment::getMeasure(Point coord) {
vector<int> timing;
Measure* measure = new Measure(Constants::ID_DISTURBANCE_NONE, timing);
bool uniformUnfixed = uniformDisturbances && fixedDisturbanceCoords.find(coord) == fixedDisturbanceCoords.end();
if(activeCellsByCoord.find(coord) != activeCellsByCoord.end()) {
if(uniformUnfixed) {
measure = activeCellsByCoord[coord]->getMeasure(uniformDisturbanceID);
return activeCellsByCoord[coord]->getMeasure(uniformDisturbanceID);
}else{
measure = activeCellsByCoord[coord]->getMeasure();
return activeCellsByCoord[coord]->getMeasure();
}
}
else if(cellsByCoord.find(coord) != cellsByCoord.end()) {
if(uniformUnfixed) {
measure = cellsByCoord[coord]->getMeasure(uniformDisturbanceID);
return cellsByCoord[coord]->getMeasure(uniformDisturbanceID);
}else{
measure = cellsByCoord[coord]->getMeasure();
return cellsByCoord[coord]->getMeasure();
}
}
return measure;
return new Measure(Constants::ID_DISTURBANCE_NONE, timing);
}
bool Environment::hasDisturbanceScheduled(Point coord) {
......@@ -241,7 +240,7 @@ void Environment::clearDisturbances() {
bool Environment::addDisturbance(Point coord, unsigned int disturbanceID, unordered_map<int, vector<int>> disturbancesTimingByYear) {
vector<int> timing;
// empty timing vector => no disturbance
Measure* measure = new Measure(Constants::ID_DISTURBANCE_NONE, timing);
Measure* measure;
if(Constants::ID_DISTURBANCE_NONE != disturbanceID && disturbancesTimingByYear.size() > 0) {
if(!disturbancesTimingByYear.empty()) {
bool relativeTiming = false;
......@@ -268,6 +267,9 @@ bool Environment::addDisturbance(Point coord, unsigned int disturbanceID, unorde
measure = new Measure(disturbanceID, timing, relativeTiming);
}
}
if(!measure) {
measure = new Measure(Constants::ID_DISTURBANCE_NONE, timing);
}
cellsByCoord[coord]->addMeasure(measure);
return measure->hasSchedule();
// TODO next line apparently only required in old version without setDisturbanceAt --> remove at some point?
......
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