plug memory leak in ldmatrix