fix memory leak from Cholmod data in SPQR support

This commit is contained in:
Desire NUENTSA 2013-05-13 13:04:12 +02:00
parent 43bb942365
commit 122b16d841

View File

@ -64,7 +64,7 @@ class SPQR
typedef PermutationMatrix<Dynamic, Dynamic> PermutationType; typedef PermutationMatrix<Dynamic, Dynamic> PermutationType;
public: public:
SPQR() SPQR()
: m_ordering(SPQR_ORDERING_DEFAULT), : m_ordering(SPQR_ORDERING_AMD),
m_allow_tol(SPQR_DEFAULT_TOL), m_allow_tol(SPQR_DEFAULT_TOL),
m_tolerance (NumTraits<Scalar>::epsilon()) m_tolerance (NumTraits<Scalar>::epsilon())
{ {
@ -72,7 +72,7 @@ class SPQR
} }
SPQR(const _MatrixType& matrix) SPQR(const _MatrixType& matrix)
: m_ordering(SPQR_ORDERING_DEFAULT), : m_ordering(SPQR_ORDERING_AMD),
m_allow_tol(SPQR_DEFAULT_TOL), m_allow_tol(SPQR_DEFAULT_TOL),
m_tolerance (NumTraits<Scalar>::epsilon()) m_tolerance (NumTraits<Scalar>::epsilon())
{ {
@ -83,10 +83,12 @@ class SPQR
~SPQR() ~SPQR()
{ {
// Calls SuiteSparseQR_free() // Calls SuiteSparseQR_free()
cholmod_free_sparse(&m_H, &m_cc); cholmod_l_free_sparse(&m_H, &m_cc);
cholmod_free_dense(&m_HTau, &m_cc); cholmod_l_free_sparse(&m_cR, &m_cc);
delete[] m_E; cholmod_l_free_dense(&m_HTau, &m_cc);
delete[] m_HPinv; std::free(m_E);
std::free(m_HPinv);
cholmod_l_finish(&m_cc);
} }
void compute(const _MatrixType& matrix) void compute(const _MatrixType& matrix)
{ {
@ -244,7 +246,7 @@ struct SPQR_QProduct : ReturnByValue<SPQR_QProduct<SPQRType,Derived> >
y_cd = viewAsCholmod(m_other.const_cast_derived()); y_cd = viewAsCholmod(m_other.const_cast_derived());
x_cd = SuiteSparseQR_qmult<Scalar>(method, m_spqr.m_H, m_spqr.m_HTau, m_spqr.m_HPinv, &y_cd, cc); x_cd = SuiteSparseQR_qmult<Scalar>(method, m_spqr.m_H, m_spqr.m_HTau, m_spqr.m_HPinv, &y_cd, cc);
res = Matrix<Scalar,ResType::RowsAtCompileTime,ResType::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x), x_cd->nrow, x_cd->ncol); res = Matrix<Scalar,ResType::RowsAtCompileTime,ResType::ColsAtCompileTime>::Map(reinterpret_cast<Scalar*>(x_cd->x), x_cd->nrow, x_cd->ncol);
cholmod_free_dense(&x_cd, cc); cholmod_l_free_dense(&x_cd, cc);
} }
const SPQRType& m_spqr; const SPQRType& m_spqr;
const Derived& m_other; const Derived& m_other;