Skip to content

Commit 3d73202

Browse files
authored
SYCL: Fix potential resource leak in the large kernel path (#5317)
1 parent 6a8badd commit 3d73202

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Src/Base/AMReX_GpuLaunch.H

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,25 @@ namespace amrex::detail {
254254
try {
255255
m_stream.queue->wait_and_throw();
256256
} catch (sycl::exception const& ex) {
257-
The_Arena()->free((void*)m_dp);
258-
m_hp->~Ls();
259-
The_Pinned_Arena()->free((void*)m_hp);
260-
m_dp = nullptr;
261-
m_hp = nullptr;
257+
if (m_dp) {
258+
The_Arena()->free((void*)m_dp);
259+
m_dp = nullptr;
260+
}
261+
if (m_hp) {
262+
m_hp->~Ls();
263+
The_Pinned_Arena()->free((void*)m_hp);
264+
m_hp = nullptr;
265+
}
262266
amrex::Abort(std::string("~SyclKernelDevPtr: ")+ex.what());
263267
}
264268
if (m_dp) {
265269
The_Arena()->free((void*)m_dp);
270+
m_dp = nullptr;
266271
}
267272
if (m_hp) {
273+
m_hp->~Ls();
268274
The_Pinned_Arena()->free((void*)m_hp);
275+
m_hp = nullptr;
269276
}
270277
}
271278
}

0 commit comments

Comments
 (0)