Fix leaked memory for successive calls to SPQR

(grafted from fe19f972e19b73a98c6e546a1521d47348128bac
)
This commit is contained in:
Desire NUENTSA 2013-09-24 15:56:56 +02:00
parent 945b0802c9
commit f5ed3421e9

View File

@ -64,7 +64,8 @@ class SPQR
typedef PermutationMatrix<Dynamic, Dynamic> PermutationType; typedef PermutationMatrix<Dynamic, Dynamic> PermutationType;
public: public:
SPQR() SPQR()
: m_ordering(SPQR_ORDERING_DEFAULT), : m_isInitialized(false),
m_ordering(SPQR_ORDERING_DEFAULT),
m_allow_tol(SPQR_DEFAULT_TOL), m_allow_tol(SPQR_DEFAULT_TOL),
m_tolerance (NumTraits<Scalar>::epsilon()) m_tolerance (NumTraits<Scalar>::epsilon())
{ {
@ -72,7 +73,8 @@ class SPQR
} }
SPQR(const _MatrixType& matrix) SPQR(const _MatrixType& matrix)
: m_ordering(SPQR_ORDERING_DEFAULT), : m_isInitialized(false),
m_ordering(SPQR_ORDERING_DEFAULT),
m_allow_tol(SPQR_DEFAULT_TOL), m_allow_tol(SPQR_DEFAULT_TOL),
m_tolerance (NumTraits<Scalar>::epsilon()) m_tolerance (NumTraits<Scalar>::epsilon())
{ {
@ -82,16 +84,22 @@ class SPQR
~SPQR() ~SPQR()
{ {
// Calls SuiteSparseQR_free() SPQR_free();
cholmod_l_finish(&m_cc);
}
void SPQR_free()
{
cholmod_l_free_sparse(&m_H, &m_cc); cholmod_l_free_sparse(&m_H, &m_cc);
cholmod_l_free_sparse(&m_cR, &m_cc); cholmod_l_free_sparse(&m_cR, &m_cc);
cholmod_l_free_dense(&m_HTau, &m_cc); cholmod_l_free_dense(&m_HTau, &m_cc);
std::free(m_E); std::free(m_E);
std::free(m_HPinv); std::free(m_HPinv);
cholmod_l_finish(&m_cc);
} }
void compute(const _MatrixType& matrix) void compute(const _MatrixType& matrix)
{ {
if(m_isInitialized) SPQR_free();
MatrixType mat(matrix); MatrixType mat(matrix);
cholmod_sparse A; cholmod_sparse A;
A = viewAsCholmod(mat); A = viewAsCholmod(mat);