diff --git a/Solver/linearSystemPETSc.cpp b/Solver/linearSystemPETSc.cpp
index f1b0cd940283596cdfb2f75254b4dabbbea0a04d..4449e515312872d5a543cf477d76ccb9541a3538 100644
--- a/Solver/linearSystemPETSc.cpp
+++ b/Solver/linearSystemPETSc.cpp
@@ -353,7 +353,11 @@ void linearSystemPETScBlockDouble::printMatlab(const char *filename) const
   PetscViewerSetFormat(viewer,PETSC_VIEWER_ASCII_MATLAB);
   printf("export mat to %s\n", filename);
   MatView(_a, viewer);
+#if (PETSC_VERSION_RELEASE == 0 || ((PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 2)))
   PetscViewerDestroy(&viewer);
+#else
+  PetscViewerDestroy(viewer);
+#endif
   return;
 }