changeset 29390:1f9e755bd91e stable

Fix occasional segfault in symbfact (bug #60101). Variables scoped to within an if block were used to populate a variable passed to cholmod library. However, when local variables went out of scope garbage collection could alter the values at runtime. * symbfact.cc: Declare *function* local variables sm (SparseMatrix) and scm (SparseComplexMatrix) and use these to populate matrix A that is passed to cholmod.
author Rik <rik@octave.org>
date Tue, 23 Feb 2021 08:53:27 -0800
parents 21a73c2a1fcb
children 98b92293bdda ce425b657693
files libinterp/corefcn/symbfact.cc
diffstat 1 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/symbfact.cc	Mon Feb 22 11:52:11 2021 +0900
+++ b/libinterp/corefcn/symbfact.cc	Tue Feb 23 08:53:27 2021 -0800
@@ -135,31 +135,34 @@
   A->stype = 1;
   A->x = &dummy;
 
+  SparseMatrix sm;
+  SparseComplexMatrix scm;
+
   if (args(0).isreal ())
     {
-      const SparseMatrix a = args(0).sparse_matrix_value ();
-      A->nrow = a.rows ();
-      A->ncol = a.cols ();
-      A->p = a.cidx ();
-      A->i = a.ridx ();
-      A->nzmax = a.nnz ();
+      sm = args(0).sparse_matrix_value ();
+      A->nrow = sm.rows ();
+      A->ncol = sm.cols ();
+      A->p = sm.cidx ();
+      A->i = sm.ridx ();
+      A->nzmax = sm.nnz ();
       A->xtype = CHOLMOD_REAL;
 
-      if (a.rows () > 0 && a.cols () > 0)
-        A->x = a.data ();
+      if (A->nrow > 0 && A->ncol > 0)
+        A->x = sm.data ();
     }
   else if (args(0).iscomplex ())
     {
-      const SparseComplexMatrix a = args(0).sparse_complex_matrix_value ();
-      A->nrow = a.rows ();
-      A->ncol = a.cols ();
-      A->p = a.cidx ();
-      A->i = a.ridx ();
-      A->nzmax = a.nnz ();
+      scm = args(0).sparse_complex_matrix_value ();
+      A->nrow = scm.rows ();
+      A->ncol = scm.cols ();
+      A->p = scm.cidx ();
+      A->i = scm.ridx ();
+      A->nzmax = scm.nnz ();
       A->xtype = CHOLMOD_COMPLEX;
 
-      if (a.rows () > 0 && a.cols () > 0)
-        A->x = a.data ();
+      if (A->nrow > 0 && A->ncol > 0)
+        A->x = scm.data ();
     }
   else
     err_wrong_type_arg ("symbfact", args(0));