# HG changeset patch # User Rik # Date 1614099207 28800 # Node ID 1f9e755bd91e278f061c21045dadab69ee1ccf47 # Parent 21a73c2a1fcb9b1057b13283c5abfeac342fd3b2 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. diff -r 21a73c2a1fcb -r 1f9e755bd91e libinterp/corefcn/symbfact.cc --- 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));