[petsc-users] Memory leak when destroying an IS created using ISConcatenate

Satish Balay balay at mcs.anl.gov
Tue Dec 16 14:10:37 CST 2014


Thanks for the report.

The following patch should fix it.

Satish
-----------

diff --git a/src/vec/is/is/utils/isdiff.c b/src/vec/is/is/utils/isdiff.c
index 6660fff..eb18ccf 100644
--- a/src/vec/is/is/utils/isdiff.c
+++ b/src/vec/is/is/utils/isdiff.c
@@ -362,6 +362,7 @@ PetscErrorCode ISConcatenate(MPI_Comm comm, PetscInt len, const IS islist[], IS
     ierr = ISGetLocalSize(islist[i], &n);CHKERRQ(ierr);
     ierr = ISGetIndices(islist[i], &iidx);CHKERRQ(ierr);
     ierr = PetscMemcpy(idx+N,iidx, sizeof(PetscInt)*n);CHKERRQ(ierr);
+    ierr = ISRestoreIndices(islist[i], &iidx);CHKERRQ(ierr);
     N   += n;
   }
   ierr = ISCreateGeneral(comm, N, idx, PETSC_OWN_POINTER, isout);CHKERRQ(ierr);

On Tue, 16 Dec 2014, Michael Souza wrote:

> There is a memory leak when destroying an IS object created with
> ISConcatenate function.
> 
> The leak can be reproduced with code below.
> 
> Cheers,
> Michael Souza
> ------------------------------------------------------------------
> static char help[] = "Memory leak in ISConcatenate function\n\n";
> #include <petscksp.h>
> #include "matblock.h"
> int main(int argc, char **args) {
>    PetscErrorCode ierr;
>    IS isa, isb, isc;
> 
>    ierr = PetscInitialize(&argc, &args, (char *) 0, help); CHKERRQ(ierr);
> 
>    ierr = ISCreateStride(PETSC_COMM_WORLD,2,0,1,&isa); CHKERRQ(ierr);
>    ierr = ISCreateStride(PETSC_COMM_WORLD,2,2,1,&isb); CHKERRQ(ierr);
> 
>    IS isarray[] = {isa, isb};
>    ierr = ISConcatenate(PETSC_COMM_WORLD,2,isarray,&isc); CHKERRQ(ierr);
> 
>    ierr = ISDestroy(&isa); CHKERRQ(ierr);
>    ierr = ISDestroy(&isb); CHKERRQ(ierr);
>    ierr = ISDestroy(&isc); CHKERRQ(ierr);
> 
>    ierr = PetscFinalize(); CHKERRQ(ierr);
>    PetscFunctionReturn(0);
> }
> ------------------------------------------------------------------
> 



More information about the petsc-users mailing list