[petsc-dev] [PATCH] Fixes a memory leak in aijviennacl destructor.
Jørgen Kvalsvik
jorgekva at stud.ntnu.no
Thu Apr 2 07:09:14 CDT 2015
The sub containers in the ViennaCL matrix were not free'd due to inversed
logic. Since delete on a nullptr won't do anything we can unconditionally call
delete on the member pointers without checking for nullptr.
---
src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx b/src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx
index d2af327..da1e348 100644
--- a/src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx
+++ b/src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx
@@ -357,10 +357,12 @@ PetscErrorCode MatDestroy_SeqAIJViennaCL(Mat A)
PetscFunctionBegin;
try {
- if (!viennaclcontainer->tempvec) delete viennaclcontainer->tempvec;
- if (!viennaclcontainer->mat) delete viennaclcontainer->mat;
- if (!viennaclcontainer->compressed_mat) delete viennaclcontainer->compressed_mat;
- delete viennaclcontainer;
+ if(viennaclcontainer) {
+ delete viennaclcontainer->tempvec;
+ delete viennaclcontainer->mat;
+ delete viennaclcontainer->compressed_mat;
+ delete viennaclcontainer;
+ }
A->valid_GPU_matrix = PETSC_VIENNACL_UNALLOCATED;
} catch(std::exception const & ex) {
SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"ViennaCL error: %s", ex.what());
--
1.9.1
More information about the petsc-dev
mailing list