Skip to content

Commit

Permalink
Fix double-free in Pilz unit tests (#3561)
Browse files Browse the repository at this point in the history
Avoid double-free of KDL::RotationalInterpolation in KDL >= 1.4.1
The underlying memory leak was fixed in KDL with orocos/orocos_kinematics_dynamics#180
  • Loading branch information
rhaschke committed Jun 6, 2024
1 parent a6c70d8 commit 4dfa3d7
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ std::unique_ptr<KDL::Path> PathCircleGenerator::circleFromCenter(const KDL::Fram
}
catch (KDL::Error_MotionPlanning&)
{
#if KDL_VERSION < ((1 << 16) | (4 << 8) | 1) // older than 1.4.1 ?
delete rot_interpo; // in case we could not construct the Path object,
// avoid a memory leak
#endif
KDL::epsilon = old_kdl_epsilon;
throw; // and pass the exception on to the caller
}
Expand Down Expand Up @@ -119,9 +123,24 @@ std::unique_ptr<KDL::Path> PathCircleGenerator::circleFromInterim(const KDL::Fra
}

KDL::RotationalInterpolation* rot_interpo = new KDL::RotationalInterpolation_SingleAxis();
return std::unique_ptr<KDL::Path>(
std::make_unique<KDL::Path_Circle>(start_pose, center_point, kdl_aux_point, goal_pose.M, alpha, rot_interpo,
eqradius, true /* take ownership of RotationalInterpolation */));
try
{
return std::unique_ptr<KDL::Path>(new KDL::Path_Circle(start_pose, center_point, kdl_aux_point, goal_pose.M, alpha,
rot_interpo, eqradius,
true /* take ownership of RotationalInterpolation */));
}
catch (KDL::Error_MotionPlanning&) // LCOV_EXCL_START // The cases where
// KDL would throw are already handled
// above,
// we keep these lines to be safe
{
#if KDL_VERSION < ((1 << 16) | (4 << 8) | 1) // older than 1.4.1 ?
delete rot_interpo; // in case we could not construct the Path object,
// avoid a memory leak
#endif
throw; // and pass the exception on to the caller
// LCOV_EXCL_STOP
}
}

double PathCircleGenerator::cosines(const double a, const double b, const double c)
Expand Down

0 comments on commit 4dfa3d7

Please sign in to comment.