I just two distinct memory leaks in pastix.c (new file attached) for 3.1 (also fixed in petsc-dev). Barry On Jan 2, 2011, at 9:42 PM, Gong Ding wrote:
Dear Barry,
It seems the patch will cause memory leak.
when valOnly is false, memory will be allocated for colptr, row and values.
99: if (!valOnly){ 100: ierr = PetscMalloc(((*n)+1) *sizeof(PetscInt) ,colptr );CHKERRQ(ierr); 101: ierr = PetscMalloc( nnz *sizeof(PetscInt) ,row);CHKERRQ(ierr); 102: ierr = PetscMalloc( nnz *sizeof(PetscScalar),values);CHKERRQ(ierr);
But at the end of function MatConvertToCSC
186: ierr = PetscMemcpy(*colptr,tmpcolptr,(*n+1)*sizeof(PetscInt));CHKERRQ(ierr); 187: ierr = PetscMalloc(((*colptr)[*n]-1)*sizeof(PetscInt),row);CHKERRQ(ierr); 188: ierr = PetscMemcpy(*row,tmprows,((*colptr)[*n]-1)*sizeof(PetscInt));CHKERRQ(ierr); 189: ierr = PetscMalloc(((*colptr)[*n]-1)*sizeof(PetscScalar),values);CHKERRQ(ierr); 190: ierr = PetscMemcpy(*values,tmpvalues,((*colptr)[*n]-1)*sizeof(PetscScalar));CHKERRQ(ierr);
memory will be allocated again. Which means when code call MatConvertToCSC next time, the memory allocated at line 100-102 will be lost.
Will you please fix this problem? i.e. check the *colptr, *row and *values, when they are not empty, skip the memory allocation at line 100-102.
Yours Gong Ding