Skip to content

Commit c6e13fd

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
Prevent null allocation in createUnifiedMemoryAllocation
Related-To: NEO-3860 Change-Id: I4b11db679385393a9059af41d71a8ce9c3f9fdc7 Signed-off-by: Gibala <krzysztof.gibala@intel.com>
1 parent 3181939 commit c6e13fd

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

core/memory_manager/unified_memory_manager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size, const Unified
101101
false};
102102

103103
GraphicsAllocation *unifiedMemoryAllocation = memoryManager->allocateGraphicsMemoryWithProperties(unifiedMemoryProperties);
104+
if (!unifiedMemoryAllocation) {
105+
return nullptr;
106+
}
104107

105108
SvmAllocationData allocData;
106109
allocData.gpuAllocation = unifiedMemoryAllocation;

unit_tests/api/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ set(IGDRCL_SRCS_tests_api
6868
${CMAKE_CURRENT_SOURCE_DIR}/cl_enqueue_write_image_tests.inl
6969
${CMAKE_CURRENT_SOURCE_DIR}/cl_finish_tests.inl
7070
${CMAKE_CURRENT_SOURCE_DIR}/cl_flush_tests.inl
71+
${CMAKE_CURRENT_SOURCE_DIR}/cl_function_pointers_tests.inl
7172
${CMAKE_CURRENT_SOURCE_DIR}/cl_get_context_info_tests.inl
7273
${CMAKE_CURRENT_SOURCE_DIR}/cl_get_device_and_host_timer.inl
7374
${CMAKE_CURRENT_SOURCE_DIR}/cl_get_device_ids_tests.inl
@@ -117,6 +118,7 @@ set(IGDRCL_SRCS_tests_api
117118
${CMAKE_CURRENT_SOURCE_DIR}/cl_set_program_specialization_constant_tests.inl
118119
${CMAKE_CURRENT_SOURCE_DIR}/cl_svm_alloc_tests.inl
119120
${CMAKE_CURRENT_SOURCE_DIR}/cl_svm_free_tests.inl
121+
${CMAKE_CURRENT_SOURCE_DIR}/cl_unified_shared_memory_tests.inl
120122
${CMAKE_CURRENT_SOURCE_DIR}/cl_unload_compiler_tests.inl
121123
${CMAKE_CURRENT_SOURCE_DIR}/cl_unload_platform_compiler_tests.inl
122124
)

unit_tests/memory_manager/unified_memory_manager_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ TEST_F(SVMMemoryAllocatorTest, whenCouldNotAllocateInMemoryManagerThenReturnsNul
123123
svmManager->freeSVMAlloc(ptr);
124124
}
125125

126+
TEST_F(SVMMemoryAllocatorTest, whenCouldNotAllocateInMemoryManagerThenCreateUnifiedMemoryAllocationReturnsNullAndDoesNotChangeAllocsMap) {
127+
FailMemoryManager failMemoryManager(executionEnvironment);
128+
svmManager->memoryManager = &failMemoryManager;
129+
130+
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties;
131+
unifiedMemoryProperties.memoryType = InternalMemoryType::DEVICE_UNIFIED_MEMORY;
132+
auto ptr = svmManager->createUnifiedMemoryAllocation(4096u, unifiedMemoryProperties);
133+
EXPECT_EQ(nullptr, ptr);
134+
EXPECT_EQ(0u, svmManager->SVMAllocs.getNumAllocs());
135+
svmManager->freeSVMAlloc(ptr);
136+
}
137+
126138
TEST_F(SVMMemoryAllocatorTest, given64kbAllowedWhenAllocatingSvmMemoryThenDontPreferRenderCompression) {
127139
MockMemoryManager memoryManager64Kb(true, false, executionEnvironment);
128140
svmManager->memoryManager = &memoryManager64Kb;

0 commit comments

Comments
 (0)