diff --git a/SPEX/SPEX_Utilities/Source/SPEX_matrix_free.c b/SPEX/SPEX_Utilities/Source/SPEX_matrix_free.c index 500ac8a2d..2a341faf4 100644 --- a/SPEX/SPEX_Utilities/Source/SPEX_matrix_free.c +++ b/SPEX/SPEX_Utilities/Source/SPEX_matrix_free.c @@ -26,14 +26,18 @@ SPEX_info SPEX_matrix_free // check inputs //-------------------------------------------------------------------------- +HERE if (!spex_initialized ( )) { return (SPEX_PANIC); } ; +HERE if (A_handle == NULL || (*A_handle) == NULL) { // nothing to free (not an error) +HERE return (SPEX_OK); } SPEX_matrix A = (*A_handle); +HERE //-------------------------------------------------------------------------- // free any non-shallow components @@ -41,9 +45,13 @@ SPEX_info SPEX_matrix_free // free the integer pattern +HERE if (!(A->p_shallow)) SPEX_FREE (A->p); +HERE if (!(A->i_shallow)) SPEX_FREE (A->i); +HERE if (!(A->j_shallow)) SPEX_FREE (A->j); +HERE // free the values if (!(A->x_shallow)) @@ -51,44 +59,66 @@ SPEX_info SPEX_matrix_free switch (A->type) { case SPEX_MPZ: +HERE if ( A->x.mpz != NULL) { +HERE for (int64_t i = 0; i < A->nzmax; i++) { +HERE +fprintf (stderr, "i: %" PRId64"\n", i) ; SPEX_MPZ_CLEAR( A->x.mpz[i]); +HERE } } +HERE SPEX_FREE (A->x.mpz); +HERE break ; case SPEX_MPQ: +HERE if ( A->x.mpq != NULL) { +HERE for (int64_t i = 0; i < A->nzmax; i++) { +HERE SPEX_MPQ_CLEAR( A->x.mpq[i]); +HERE } } +HERE SPEX_FREE (A->x.mpq); break ; case SPEX_MPFR: +HERE if ( A->x.mpfr != NULL) { +HERE for (int64_t i = 0; i < A->nzmax; i++) { +HERE SPEX_MPFR_CLEAR( A->x.mpfr[i]); +HERE } } +HERE SPEX_FREE (A->x.mpfr); +HERE break ; case SPEX_INT64: +HERE SPEX_FREE (A->x.int64); +HERE break ; case SPEX_FP64: +HERE SPEX_FREE (A->x.fp64); +HERE break ; default: @@ -99,15 +129,20 @@ SPEX_info SPEX_matrix_free // A->scale is never shallow +HERE SPEX_MPQ_CLEAR (A->scale); +HERE //-------------------------------------------------------------------------- // free the header //-------------------------------------------------------------------------- // the header is never shallow +HERE SPEX_FREE (A); +HERE (*A_handle) = NULL ; +HERE return (SPEX_OK); }