Minor code cleanup

prevent nullptr dereference

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2021-07-22 17:48:33 +00:00
committed by Compute-Runtime-Automation
parent c2ab7fcf70
commit 575445dbb5
3 changed files with 9 additions and 4 deletions

View File

@@ -74,7 +74,9 @@ StackVec<GraphicsAllocation *, 1> const &MultiGraphicsAllocation::getGraphicsAll
void MultiGraphicsAllocation::setMultiStorage(bool value) {
isMultiStorage = value;
if (isMultiStorage && !migrationSyncData) {
migrationSyncData = createMigrationSyncDataFunc(getDefaultGraphicsAllocation()->getUnderlyingBufferSize());
auto graphicsAllocation = getDefaultGraphicsAllocation();
UNRECOVERABLE_IF(!graphicsAllocation);
migrationSyncData = createMigrationSyncDataFunc(graphicsAllocation->getUnderlyingBufferSize());
migrationSyncData->incRefInternal();
}
}

View File

@@ -255,6 +255,12 @@ TEST_F(MigrationSyncDataTests, whenMigrationSyncDataExistsAndSetMultiStorageIsCa
EXPECT_EQ(migrationSyncData, multiGraphicsAllocation.getMigrationSyncData());
}
TEST(MigrationSyncDataTest, givenEmptyMultiGraphicsAllocationWhenSetMultiStorageIsCalledThenAbortIsCalled) {
MultiGraphicsAllocation multiGraphicsAllocation(1);
EXPECT_EQ(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation());
EXPECT_THROW(multiGraphicsAllocation.setMultiStorage(true), std::exception);
}
TEST_F(MigrationSyncDataTests, whenMigrationIsNotStartedThenMigrationIsNotInProgress) {
EXPECT_FALSE(migrationSyncData->isMigrationInProgress());