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:
parent
187bfefe28
commit
e1458fc95c
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue