[petsc-dev] [PATCH] Fixes a memory leak in aijviennacl destructor.
Karl Rupp
rupp at iue.tuwien.ac.at
Thu Apr 2 10:50:59 CDT 2015
Hi Jørgen,
thanks for the patch. The fix is in branch
karlrupp/fix-aijviennacl-destruction and has been merged to master and
next. It also adds an explicit constructor so that the struct-members
are explicitly initialized to NULL.
Thanks and best regards,
Karli
On 04/02/2015 02:09 PM, Jørgen Kvalsvik wrote:
> 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());
>
More information about the petsc-dev
mailing list