Libmv: Fix memory leak in modal solver
The leak was happening when problem did not have any parameters blocks defined. This happens, for example, if there are no 3D points at all, or when all markers are set to 0 weight. Was noticeable in libmv_modal_solver_test when building with LSAN enabled.
This commit is contained in:
parent
590220e451
commit
df5b65811e
|
@ -175,8 +175,9 @@ void ModalSolver(const Tracks &tracks,
|
|||
// STEP 2: Refine rotation with Ceres.
|
||||
ceres::Problem problem;
|
||||
|
||||
ceres::LocalParameterization* quaternion_parameterization =
|
||||
new ceres::QuaternionParameterization;
|
||||
// NOTE: Parameterization is lazily initialized when it is really needed,
|
||||
// and is re-used by all parameters block.
|
||||
ceres::LocalParameterization* quaternion_parameterization = NULL;
|
||||
|
||||
int num_residuals = 0;
|
||||
for (int i = 0; i < all_markers.size(); ++i) {
|
||||
|
@ -195,6 +196,10 @@ void ModalSolver(const Tracks &tracks,
|
|||
&quaternion(0));
|
||||
num_residuals++;
|
||||
|
||||
if (quaternion_parameterization == NULL) {
|
||||
quaternion_parameterization = new ceres::QuaternionParameterization();
|
||||
}
|
||||
|
||||
problem.SetParameterization(&quaternion(0),
|
||||
quaternion_parameterization);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue