diff --git a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp index d38f5e8490..fd4fb2bc3c 100644 --- a/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp +++ b/level_zero/tools/source/sysman/linux/os_sysman_imp.cpp @@ -119,8 +119,12 @@ LinuxSysmanImp::LinuxSysmanImp(SysmanDeviceImp *pParentSysmanDeviceImp) { void LinuxSysmanImp::releasePmtObject() { for (auto &subDeviceIdToPmtEntry : mapOfSubDeviceIdToPmtObject) { - delete subDeviceIdToPmtEntry.second; + if (subDeviceIdToPmtEntry.second) { + delete subDeviceIdToPmtEntry.second; + subDeviceIdToPmtEntry.second = nullptr; + } } + mapOfSubDeviceIdToPmtObject.clear(); } LinuxSysmanImp::~LinuxSysmanImp() { diff --git a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp index ca3bd43d66..70b0b8d120 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/linux/pmt/test_pmt.cpp @@ -236,6 +236,18 @@ TEST_F(ZesPmtFixtureMultiDevice, GivenOpenSyscallFailWhenDoingPMTInitThenPMTmapO } } +TEST_F(ZesPmtFixtureMultiDevice, GivenNoPMTHandleInmapOfSubDeviceIdToPmtObjectWhenCallingreleasePmtObjectThenMapWouldGetEmpty) { + auto mapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject; + for (const auto &deviceHandle : deviceHandles) { + ze_device_properties_t deviceProperties = {}; + Device::fromHandle(deviceHandle)->getProperties(&deviceProperties); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.emplace(deviceProperties.subdeviceId, nullptr); + } + pLinuxSysmanImp->releasePmtObject(); + EXPECT_TRUE(pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.empty()); + pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject = mapOriginal; +} + class ZesPmtFixtureNoSubDevice : public SysmanDeviceFixture { protected: std::vector deviceHandles;