Skip to content

Commit

Permalink
resolve memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Kei18 committed Feb 12, 2021
1 parent 9b48e60 commit c2a82c3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions visualizer/include/mapfplan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ struct MAPFPlan {
Config config_s; // start configuration
Config config_g; // goal configuration
Configs transitions; // plan

~MAPFPlan() { delete G; }
};
2 changes: 1 addition & 1 deletion visualizer/include/ofApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ofApp : public ofBaseApp {

public:
ofApp(MAPFPlan* _P);
~ofApp() {};
~ofApp();
void setup();
void update();
void draw();
Expand Down
6 changes: 2 additions & 4 deletions visualizer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ int main(int argc, char *argv[]) {
return 0;
}

MAPFPlan* solution = new MAPFPlan;
MAPFPlan* solution = new MAPFPlan; // deleted in ofApp destructor
readSetResult(argv[1], solution);
ofSetupOpenGL(100, 100, OF_WINDOW);
ofRunApp(new ofApp(solution));

delete solution;
return 0;
}

Expand Down Expand Up @@ -63,7 +61,7 @@ void readSetResult(const std::string& result_file, MAPFPlan* plan)
while (getline(file, line)) {
// read map
if (std::regex_match(line, results, r_map)) {
plan->G = new Grid(results[1].str());
plan->G = new Grid(results[1].str()); // deleted in destructor of MAPFPlan
continue;
}
// set agent num
Expand Down
5 changes: 5 additions & 0 deletions visualizer/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ ofApp::ofApp(MAPFPlan* _P): P(_P)
line_mode = LINE_MODE::STRAIGHT;
}

ofApp::~ofApp()
{
delete P;
}

void ofApp::setup()
{
// setup size
Expand Down

0 comments on commit c2a82c3

Please sign in to comment.