From 4dbfa5483b57465262a98b312475cee25b433cd9 Mon Sep 17 00:00:00 2001 From: Stan Gerald Moore Date: Tue, 27 Feb 2024 14:50:20 -0700 Subject: [PATCH] Fix memory leak --- src/KOKKOS/comm_tiled_kokkos.cpp | 3 ++- src/comm_tiled.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/comm_tiled_kokkos.cpp b/src/KOKKOS/comm_tiled_kokkos.cpp index 60e7f7d9a8..bd65bcf221 100644 --- a/src/KOKKOS/comm_tiled_kokkos.cpp +++ b/src/KOKKOS/comm_tiled_kokkos.cpp @@ -36,6 +36,7 @@ static constexpr int BUFEXTRA = 1000; CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) { + sendlist = nullptr; } /* ---------------------------------------------------------------------- */ @@ -47,6 +48,7 @@ CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp) : CommTiled(_lmp) CommTiledKokkos::CommTiledKokkos(LAMMPS *_lmp, Comm *oldcomm) : CommTiled(_lmp,oldcomm) { + sendlist = nullptr; } /* ---------------------------------------------------------------------- */ @@ -57,7 +59,6 @@ CommTiledKokkos::~CommTiledKokkos() sendlist = nullptr; buf_send = nullptr; buf_recv = nullptr; - maxswap = 0; } /* ---------------------------------------------------------------------- */ diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 59ab993655..b864e0523d 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -2468,8 +2468,10 @@ void CommTiled::deallocate_swap(int n) delete [] maxsendlist[i]; - for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); - delete [] sendlist[i]; + if (sendlist && sendlist[i]) { + for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); + delete [] sendlist[i]; + } } delete [] sendproc;