fixed memory leaks in lst_to_matrix() and diag_matrix()