Skip to content

Commit d98b61a

Browse files
authored
[SYCL][L0] Fix memory leak for piCommandListFenceMap. (#2931)
std::map::[]operator should not be used to lookup the existence of the map entry because it creates a place-holder entry if the entry does not exist. This leads to a memory leak because the place-holder won't be explictly deallocated. Instead, we should use std::map::find() to check if a map entry exists or not. Signed-off-by: Byoungro So <[email protected]>
1 parent 16b3ffe commit d98b61a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,10 @@ pi_result _pi_device::getAvailableCommandList(
530530

531531
if (Queue->Device->ZeCommandListCache.size() > 0) {
532532
*ZeCommandList = Queue->Device->ZeCommandListCache.front();
533-
*ZeFence = Queue->ZeCommandListFenceMap[*ZeCommandList];
534-
if (*ZeFence == nullptr) {
533+
auto it = Queue->ZeCommandListFenceMap.find(*ZeCommandList);
534+
if (it != Queue->ZeCommandListFenceMap.end()) {
535+
*ZeFence = it->second;
536+
} else {
535537
// If there is a command list available on this device, but no
536538
// fence yet associated, then we must create a fence/list
537539
// reference for this Queue. This can happen if two Queues reuse

0 commit comments

Comments
 (0)