[petsc-users] [PATCH 1/2] Close memory leaks

Jed Brown jedbrown at mcs.anl.gov
Sun Sep 8 00:54:49 CDT 2013


---
 ex2.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/ex2.c b/ex2.c
index 8762937..82f1d97 100644
--- a/ex2.c
+++ b/ex2.c
@@ -28,11 +28,13 @@ int main(int argc,char **args)
   MatCreate(PETSC_COMM_WORLD,&A);
   MatSetType(A,MATSEQAIJ);
   MatLoad(A, viewer1);
+  PetscViewerDestroy(&viewer1);
   /* ----- */
   ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"b.bin",
                                FILE_MODE_READ,&viewer2);
   VecCreate(PETSC_COMM_WORLD,&b);
   VecLoad(b,viewer2);
+  PetscViewerDestroy(&viewer2);
   /* ---- */
   MatView(A,PETSC_VIEWER_STDOUT_WORLD);
   VecView(b,PETSC_VIEWER_STDOUT_WORLD);
@@ -54,6 +56,8 @@ int main(int argc,char **args)
 
   PCFieldSplitSetIS(pc, "1", is_row1);
   PCFieldSplitSetIS(pc, "2", is_row2);
+  ISDestroy(&is_row1);
+  ISDestroy(&is_row2);
   
   KSPSetFromOptions(ksp);
   
-- 
1.8.4



More information about the petsc-users mailing list