To avoid seg fault, add null check before deleting PMT objects

Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
Jitendra Sharma 2021-05-17 16:59:16 +00:00 committed by Compute-Runtime-Automation
parent 187bfefe28
commit e1458fc95c
2 changed files with 17 additions and 1 deletions

View File

@ -119,9 +119,13 @@ LinuxSysmanImp::LinuxSysmanImp(SysmanDeviceImp *pParentSysmanDeviceImp) {
void LinuxSysmanImp::releasePmtObject() {
for (auto &subDeviceIdToPmtEntry : mapOfSubDeviceIdToPmtObject) {
if (subDeviceIdToPmtEntry.second) {
delete subDeviceIdToPmtEntry.second;
subDeviceIdToPmtEntry.second = nullptr;
}
}
mapOfSubDeviceIdToPmtObject.clear();
}
LinuxSysmanImp::~LinuxSysmanImp() {
if (nullptr != pSysfsAccess) {

View File

@ -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<ze_device_handle_t> deviceHandles;