From 5bf5ba779eba62b0a4e057207ff6c8e160edae5b Mon Sep 17 00:00:00 2001 From: Colin Davidson Date: Mon, 18 Dec 2023 14:55:00 +0000 Subject: [PATCH] Fix asan memory leaks in UnitCL shared alloc tests Some USM Shared alloc tests were added which showed up in asan that there were memory leaks from calls to clSharedMemAlloc. This fixes these by calling clMemBlockingFreeINTEL. --- .../usm_allocate.cpp | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/source/cl/test/UnitCL/source/cl_intel_unified_shared_memory/usm_allocate.cpp b/source/cl/test/UnitCL/source/cl_intel_unified_shared_memory/usm_allocate.cpp index e76bebcfe..f121d14ed 100644 --- a/source/cl/test/UnitCL/source/cl_intel_unified_shared_memory/usm_allocate.cpp +++ b/source/cl/test/UnitCL/source/cl_intel_unified_shared_memory/usm_allocate.cpp @@ -446,6 +446,10 @@ TEST_F(USMTests, SingleSharedMemAlloc_ValidUsage) { EXPECT_TRUE(shared_ptr != nullptr); } + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } shared_ptr = clSharedMemAllocINTEL(context, device, nullptr, bytes, 0, &err); if (!shared_mem_support) { EXPECT_EQ_ERRCODE(err, CL_INVALID_OPERATION); @@ -455,6 +459,11 @@ TEST_F(USMTests, SingleSharedMemAlloc_ValidUsage) { EXPECT_TRUE(shared_ptr != nullptr); } + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } + const cl_mem_properties_intel no_properties[] = {0}; shared_ptr = clSharedMemAllocINTEL(context, device, no_properties, bytes, align, &err); @@ -465,7 +474,10 @@ TEST_F(USMTests, SingleSharedMemAlloc_ValidUsage) { EXPECT_SUCCESS(err); EXPECT_TRUE(shared_ptr != nullptr); } - + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } const cl_mem_properties_intel properties[] = {CL_MEM_ALLOC_FLAGS_INTEL, 0, 0}; shared_ptr = clSharedMemAllocINTEL(context, device, properties, bytes, align, &err); @@ -476,6 +488,10 @@ TEST_F(USMTests, SingleSharedMemAlloc_ValidUsage) { EXPECT_SUCCESS(err); EXPECT_TRUE(shared_ptr != nullptr); } + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } } // Test for invalid API usage of clSharedMemAllocINTEL without an associated @@ -590,6 +606,10 @@ TEST_F(USMTests, CrossSharedMemAlloc_ValidUsage) { EXPECT_SUCCESS(err); EXPECT_TRUE(shared_ptr != nullptr); } + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } shared_ptr = clSharedMemAllocINTEL(context, nullptr, nullptr, bytes, 0, &err); if (!shared_mem_support) { @@ -599,6 +619,10 @@ TEST_F(USMTests, CrossSharedMemAlloc_ValidUsage) { EXPECT_SUCCESS(err); EXPECT_TRUE(shared_ptr != nullptr); } + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } const cl_mem_properties_intel no_properties[] = {0}; shared_ptr = clSharedMemAllocINTEL(context, nullptr, no_properties, bytes, @@ -610,6 +634,10 @@ TEST_F(USMTests, CrossSharedMemAlloc_ValidUsage) { EXPECT_SUCCESS(err); EXPECT_TRUE(shared_ptr != nullptr); } + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } const cl_mem_properties_intel properties[] = {CL_MEM_ALLOC_FLAGS_INTEL, 0, 0}; shared_ptr = @@ -621,6 +649,10 @@ TEST_F(USMTests, CrossSharedMemAlloc_ValidUsage) { EXPECT_SUCCESS(err); EXPECT_TRUE(shared_ptr != nullptr); } + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } } using USMAllocFlagTest = USMWithParam; @@ -703,8 +735,10 @@ TEST_P(USMAllocFlagTest, SharedAlloc) { EXPECT_SUCCESS(err); EXPECT_TRUE(shared_ptr != nullptr); - err = clMemBlockingFreeINTEL(context, shared_ptr); - EXPECT_SUCCESS(err); + if (shared_ptr) { + err = clMemBlockingFreeINTEL(context, shared_ptr); + EXPECT_SUCCESS(err); + } } INSTANTIATE_TEST_SUITE_P(