diff --git a/lib/ldpc/mod2dense.c b/lib/ldpc/mod2dense.c index 2384b32b5..35a207122 100755 --- a/lib/ldpc/mod2dense.c +++ b/lib/ldpc/mod2dense.c @@ -65,9 +65,11 @@ mod2dense *mod2dense_allocate void mod2dense_free ( mod2dense *m /* Matrix to free */ ) -{ free(m->bits); - free(m->col); - free(m); +{ if (m) + { free(m->bits); + free(m->col); + free(m); + } } diff --git a/lib/ldpc/mod2sparse.c b/lib/ldpc/mod2sparse.c index 66e66799d..f3f9ba9f6 100755 --- a/lib/ldpc/mod2sparse.c +++ b/lib/ldpc/mod2sparse.c @@ -114,13 +114,17 @@ void mod2sparse_free { mod2block *b; - free(m->rows); - free(m->cols); + if (m) + { free(m->rows); + free(m->cols); - while (m->blocks!=0) - { b = m->blocks; - m->blocks = b->next; - free(b); + while (m->blocks!=0) + { b = m->blocks; + m->blocks = b->next; + free(b); + } + + free (m); } } @@ -1186,7 +1190,7 @@ int mod2sparse_decomp cc2 = 0; for (j = 0; jk || cc3==k && cc>0) + if (cc3>k || (cc3==k && cc>0)) { if (cc3==k) cc -= 1; for (;;) { f = mod2sparse_first_in_col(B,j); diff --git a/lib/ldpc/rcode.c b/lib/ldpc/rcode.c index 5c7f2e8c8..84d6fd923 100755 --- a/lib/ldpc/rcode.c +++ b/lib/ldpc/rcode.c @@ -199,11 +199,19 @@ garbled: exit(1); } -// Fortran interface routine for WSJT-X +// Fortran interface routines for WSJT-X void init_ldpc_ (char *pfile, char *gfile ) { - char *pchk_file,*gen_file; read_pchk( pfile ); read_gen( gfile, 0, 0 ); } +void fini_ldpc_ () +{ + mod2dense_free (G); + mod2sparse_free (U); + mod2sparse_free (L); + free (cols); + free (rows); + mod2sparse_free (H); +}