Major memory leak in Lshaped testcase
I ran a vasic valgrind analysis on the Lshaped testcase (with max_number_iterations=2). Numerous issues are reported (see memcheck.log)
Most critical ones seem to be the 2 'definitely lost' (around line 1624), e.g.:
==30008== 5,787,792 bytes in 1 blocks are definitely lost in loss record 83 of 83 ==30008== at 0x4A079EE: malloc (vg_replace_malloc.c:270) ==30008== by 0x8C5A027: taucs_dccs_create (in /home/cenaero/pierard/TLS/lib/x86_64_Linux_Debug/libTaucs.so) ==30008== by 0x8C5BED7: taucs_dccs_permute_symmetrically (in /home/cenaero/pierard/TLS/lib/x86_64_Linux_Debug/libTaucs.so) ==30008== by 0x8C447FD: lalg::xLinearSystemSolverTaucsBase::permuteSymmetrically(void*, int*, int*) (xLinearSystemSolverTaucs.cc:269) ==30008== by 0x547DB29: lalg::xLinearSystemSolverTaucs<double>::reorder(int*, int*, int**) (xLinearSystemSolverTaucs_imp.h:171) ==30008== by 0x547C883: lalg::xLinearSystemSolverTaucs<double>::symb() (xLinearSystemSolverTaucs_imp.h:277) ==30008== by 0x547E139: void lalg::xLinearSystemSolverTaucs<double>::connectMatrix<lalg::xGenericSparseMatrix<double, xTraitMatrixDefinitePositive, xTraitMatrixLowerSym, xTraitMatrixSparceCSC, xTraitMatrixCindex> >(lalg::xGenericSparseMatrix<double, xTraitMatrixDefinitePositive, xTraitMatrixLowerSym, xTraitMatrixSparceCSC, xTraitMatrixCindex>&) (xLinearSystemSolverTaucs_imp.h:229) ==30008== by 0x54D9BC5: void DamageGrowthMechanics::resolveMechanicalProblem_V1<lalg::xLinearSystemSolverTaucs<double>, lalg::xGenericSparseMatrix<double, xTraitMatrixDefinitePositive, xTraitMatrixLowerSym, xTraitMatrixSparceCSC, xTraitMatrixCindex>, xEvalIsotropDamagedHooke2DPlaneStrain, xEvalIsotropDamagedStress2DPlaneStrain, xEvalIsotropElasticHook2DPlaneStrain, xtls::xEvalTLSDamageFunction>(lalg::xLinearSystemSolverTaucs<double>&, xEvalIsotropDamagedHooke2DPlaneStrain&, xEvalIsotropDamagedStress2DPlaneStrain&, xEvalIsotropElasticHook2DPlaneStrain&, xfem::xEvalGradField<xfem::xSymmetrize, xfem::xField>&, xtls::xEvalTLSDamageFunction&, int) (DamageGrowthMechanics.ipp:277) ==30008== by 0x54D7426: void DamageGrowthMechanics::compute_elastic<lalg::xLinearSystemSolverTaucs<double>, lalg::xGenericSparseMatrix<double, xTraitMatrixDefinitePositive, xTraitMatrixLowerSym, xTraitMatrixSparceCSC, xTraitMatrixCindex> >(lalg::xLinearSystemSolverTaucs<double>&) (DamageGrowthMechanics.ipp:84) ==30008== by 0x54CC6B3: DamageTestMesh::run() (DamageTest.cc:608) ==30008== by 0x42F04F: DamageTestContext<DamageTestMesh>::run_test() (DamageTest.h:117) ==30008== by 0x42D8F8: main (main.cc:100)
A very first analysis shows that:
- Matrices are allocated within TAUCS, but should be freed outside taucs
- xLinearSystemSolverTaucsBase::PAPT stores the result of the call to taucs_dccs_permute_symmetrically
- This should be freed in destructor of xLinearSystemSolverTaucsBase, as it is implemented (with free instead of taucs_free - but that's another debate...)
- BUT call to to destructor of xLinearSystemSolverTaucsBase or xLinearSystemSolverTaucs is never done !!!
- I guess this should be done in DamageTest, but I'm a little bit lost with all these templates and typedefs...