Don't access command stream receivers when vector is empty

Change-Id: I1011b94be1ec7f28b71659c27b09b93e577769e2
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2018-10-04 08:50:20 +02:00
committed by sys_ocldev
parent 61000c0dd4
commit 77bbd2b89b
2 changed files with 17 additions and 1 deletions

View File

@ -300,7 +300,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
releaseResidencyLock();
UNRECOVERABLE_IF(DebugManager.flags.CreateMultipleDevices.get() == 0 &&
gfxAllocation->taskCount != ObjectNotUsed &&
gfxAllocation->taskCount != ObjectNotUsed && this->executionEnvironment.commandStreamReceivers.size() > 0 &&
this->getCommandStreamReceiver(0) && this->getCommandStreamReceiver(0)->getTagAddress() &&
gfxAllocation->taskCount > *this->getCommandStreamReceiver(0)->getTagAddress());

View File

@ -13,6 +13,7 @@
#include "runtime/os_interface/os_library.h"
#include "runtime/os_interface/windows/os_context_win.h"
#include "runtime/platform/platform.h"
#include "runtime/utilities/tag_allocator.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_deferred_deleter.h"
@ -2223,3 +2224,18 @@ TEST_F(WddmMemoryManagerTest2, givenReadOnlyMemoryPassedToPopulateOsHandlesWhenC
handleStorage.fragmentStorageData[1].freeTheFragment = true;
memoryManager->cleanOsHandles(handleStorage);
}
TEST(WddmMemoryManagerCleanupTest, givenUsedTagAllocationInWddmMemoryManagerWhenCleanupMemoryManagerThenDontAccessCsr) {
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init());
ExecutionEnvironment executionEnvironment;
executionEnvironment.commandStreamReceivers.push_back(std::unique_ptr<CommandStreamReceiver>(createCommandStream(*platformDevices, executionEnvironment)));
executionEnvironment.memoryManager = std::make_unique<WddmMemoryManager>(false, false, wddm.get(), executionEnvironment);
EXPECT_EQ(executionEnvironment.commandStreamReceivers[0].get(), executionEnvironment.memoryManager->getCommandStreamReceiver(0));
auto tagAllocator = executionEnvironment.memoryManager->getEventPerfCountAllocator();
auto allocation = tagAllocator->getTag()->getGraphicsAllocation();
allocation->taskCount = 1;
executionEnvironment.commandStreamReceivers.clear();
EXPECT_THROW(executionEnvironment.memoryManager->getCommandStreamReceiver(0), std::exception);
EXPECT_NO_THROW(executionEnvironment.memoryManager.reset());
}