Thanks everyone. All those emails help.
> [EMAIL PROTECTED] wrote: >> Hey All: >> >> Is there a way we can avoid Segmentation fault error when we try to free >> a >> gsl_matrix that was never allocated, or that has already been freed? >> > If you don't allocate the matrix b when you declare it, try using > > gsl_matrix b = 0; > > Then you can free it using > > if( b != 0 ){ > gsl_matrix_free( b ); > b = 0; > } > > without worrying about whether b was allocated or already freed. This is > a standard technique and useful when you have conditional blocks of code > that may or may not allocate or free the matrix. If you want some > debugging information you can add an else to the delete block: > > else { > // print some message about b not being allocated. > } > > There are three likely reasons for gsl_matrix_free failing. First, you > may have bugs in your code. In that case you might try printing a > message whenever b is allocated or deleted or running a debugger that > traces what happens to b. Second, you may have b allocated > conditionally. The code above deals with this. Third, gsl_matrix_alloc > or gsl_matrix_free could fail for reasons not related to the first two. > Exceptions are only really designed to handle the third case. > > -- > JDL > > > > _______________________________________________ > Help-gsl mailing list > Help-gsl@gnu.org > http://lists.gnu.org/mailman/listinfo/help-gsl > _______________________________________________ Help-gsl mailing list Help-gsl@gnu.org http://lists.gnu.org/mailman/listinfo/help-gsl