From 501729a84cd0aeef0ae2fcf24cc832eafaf0fa13 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 15 Sep 2017 12:15:02 +0200 Subject: [PATCH] fix possible memory leak in Robot module --- src/Mod/Robot/App/Trajectory.cpp | 33 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Mod/Robot/App/Trajectory.cpp b/src/Mod/Robot/App/Trajectory.cpp index d1ae52555e..24d9b473a9 100644 --- a/src/Mod/Robot/App/Trajectory.cpp +++ b/src/Mod/Robot/App/Trajectory.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif #include @@ -153,11 +154,10 @@ void Trajectory::generateTrajectory(void) pcTrajectory = new KDL::Trajectory_Composite(); // pointer to the pieces while iterating - KDL::Trajectory_Segment *pcTrak=0; - KDL::Path *pcPath=0; - KDL::VelocityProfile *pcVelPrf=0; - KDL::Path_RoundedComposite *pcRoundComp=0; - KDL::Frame Last; + std::unique_ptr pcTrak; + std::unique_ptr pcVelPrf; + std::unique_ptr pcRoundComp; + KDL::Frame Last; try { // handle the first waypoint special @@ -177,11 +177,11 @@ void Trajectory::generateTrajectory(void) // continues the movement until no continus waypoint or the end bool Cont = (*it)->Cont && !(it==--vpcWaypoints.end()); // start of a continue block - if (Cont && pcRoundComp==0) { - pcRoundComp = new KDL::Path_RoundedComposite(3, 3, - new KDL::RotationalInterpolation_SingleAxis()); + if (Cont && !pcRoundComp) { + pcRoundComp.reset(new KDL::Path_RoundedComposite(3, 3, + new KDL::RotationalInterpolation_SingleAxis())); // the velocity of the first waypoint is used - pcVelPrf = new KDL::VelocityProfile_Trap((*it)->Velocity,(*it)->Accelaration); + pcVelPrf.reset(new KDL::VelocityProfile_Trap((*it)->Velocity,(*it)->Accelaration)); pcRoundComp->Add(Last); pcRoundComp->Add(Next); @@ -196,21 +196,22 @@ void Trajectory::generateTrajectory(void) pcRoundComp->Add(Next); pcRoundComp->Finish(); pcVelPrf->SetProfile(0,pcRoundComp->PathLength()); - pcTrak = new KDL::Trajectory_Segment(pcRoundComp,pcVelPrf); - pcRoundComp = 0; + pcTrak.reset(new KDL::Trajectory_Segment(pcRoundComp.release(),pcVelPrf.release())); // normal block } - else if (Cont==false && pcRoundComp==0){ + else if (Cont==false && !pcRoundComp){ + KDL::Path* pcPath; pcPath = new KDL::Path_Line(Last, Next, new KDL::RotationalInterpolation_SingleAxis(), 1.0, true ); - pcVelPrf = new KDL::VelocityProfile_Trap((*it)->Velocity,(*it)->Accelaration); + + pcVelPrf.reset(new KDL::VelocityProfile_Trap((*it)->Velocity,(*it)->Accelaration)); pcVelPrf->SetProfile(0,pcPath->PathLength()); - pcTrak = new KDL::Trajectory_Segment(pcPath,pcVelPrf); + pcTrak.reset(new KDL::Trajectory_Segment(pcPath,pcVelPrf.release())); } Last = Next; break;} @@ -221,8 +222,8 @@ void Trajectory::generateTrajectory(void) } // add the segment if no continuous block is running - if (!pcRoundComp) - pcTrajectory->Add(pcTrak); + if (!pcRoundComp && pcTrak) + pcTrajectory->Add(pcTrak.release()); } } }