changeset 21584:ee1a009dd60f

Fix memory leak using cholmod library (bug #47372). * sparse-chol.cc (~sparse_chol_rep): Free Lsparse array if allocated. Always free Common memory. * sparse-chol.cc (sparse_chol_rep::init): Always free Lfactor.
author Rik <rik@octave.org>
date Sun, 03 Apr 2016 18:09:56 -0700
parents d5963a6e29c2
children bad3ed83330d
files liboctave/numeric/sparse-chol.cc
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/numeric/sparse-chol.cc	Sat Apr 02 15:23:56 2016 -0700
+++ b/liboctave/numeric/sparse-chol.cc	Sun Apr 03 18:09:56 2016 -0700
@@ -68,8 +68,10 @@
   ~sparse_chol_rep (void)
   {
 #ifdef HAVE_CHOLMOD
-    if (is_pd)
+    if (Lsparse)
       CHOLMOD_NAME (free_sparse) (&Lsparse, &Common);
+
+    CHOLMOD_NAME(finish) (&Common);
 #endif
   }
 
@@ -318,15 +320,15 @@
           for (octave_idx_type i = 0; i < a_nr; i++)
             perms(i) = static_cast<octave_idx_type *>(Lfactor->Perm)[i];
         }
+    }
 
-      static char tmp[] = " ";
+  // NAME used to prefix statistics report from print_common
+  static char blank_name[] = " ";
 
-      BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
-      CHOLMOD_NAME(free_factor) (&Lfactor, cm);
-      CHOLMOD_NAME(finish) (cm);
-      CHOLMOD_NAME(print_common) (tmp, cm);
-      END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
-    }
+  BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
+  CHOLMOD_NAME(print_common) (blank_name, cm);
+  CHOLMOD_NAME(free_factor) (&Lfactor, cm);
+  END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
 
   return info;