From b3ea52c113992dc6dfbee3c73236837b0fe8614a Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 18 Jul 2023 17:49:57 +0100 Subject: [PATCH 1/3] [coverity] Fix 1566349 Resource leak Ensure that the `ur_loader_config_handle_t` is always cleaned up even in the event of assert failures in `SetUp()` by releasing it in `TearDown()`. --- test/layers/validation/fixtures.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/layers/validation/fixtures.hpp b/test/layers/validation/fixtures.hpp index 11e2a33f24..6af67c6f00 100644 --- a/test/layers/validation/fixtures.hpp +++ b/test/layers/validation/fixtures.hpp @@ -12,20 +12,24 @@ struct urTest : ::testing::Test { void SetUp() override { - ur_loader_config_handle_t config; - ASSERT_EQ(urLoaderConfigCreate(&config), UR_RESULT_SUCCESS); - ASSERT_EQ(urLoaderConfigEnableLayer(config, "UR_LAYER_FULL_VALIDATION"), + ASSERT_EQ(urLoaderConfigCreate(&loader_config), UR_RESULT_SUCCESS); + ASSERT_EQ(urLoaderConfigEnableLayer(loader_config, + "UR_LAYER_FULL_VALIDATION"), UR_RESULT_SUCCESS); - ur_device_init_flags_t device_flags = 0; - ASSERT_EQ(urInit(device_flags, config), UR_RESULT_SUCCESS); - ASSERT_EQ(urLoaderConfigRelease(config), UR_RESULT_SUCCESS); + ASSERT_EQ(urInit(device_flags, loader_config), UR_RESULT_SUCCESS); + ASSERT_EQ(urLoaderConfigRelease(loader_config), UR_RESULT_SUCCESS); } void TearDown() override { + if (loader_config) { + ASSERT_EQ(urLoaderConfigRelease(loader_config), UR_RESULT_SUCCESS); + } ur_tear_down_params_t tear_down_params{}; ASSERT_EQ(urTearDown(&tear_down_params), UR_RESULT_SUCCESS); } + + ur_loader_config_handle_t loader_config = nullptr; }; struct valPlatformsTest : urTest { From 19fdd60cfc274dae7f2a63d3b837ff9a5cf6e642 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 18 Jul 2023 17:55:31 +0100 Subject: [PATCH 2/3] [coverity] Fix 1566348 Uninitialized scalar field Default initialize the `enableParameterValidation` and `enableLeakChecking` data members of the `ur_validation_layer::context_t` object. --- source/loader/layers/validation/ur_validation_layer.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/loader/layers/validation/ur_validation_layer.hpp b/source/loader/layers/validation/ur_validation_layer.hpp index 7a103568ca..3201a5345e 100644 --- a/source/loader/layers/validation/ur_validation_layer.hpp +++ b/source/loader/layers/validation/ur_validation_layer.hpp @@ -20,8 +20,8 @@ namespace ur_validation_layer { /////////////////////////////////////////////////////////////////////////////// class __urdlllocal context_t : public proxy_layer_context_t { public: - bool enableParameterValidation; - bool enableLeakChecking; + bool enableParameterValidation = false; + bool enableLeakChecking = false; logger::Logger logger; ur_dditable_t urDdiTable = {}; From 38141b3e59634c3abb06ebdd8b3ba1be2c9793fc Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 18 Jul 2023 18:00:10 +0100 Subject: [PATCH 3/3] [coverity] Fix 1566349 Resource leak Move `ur_loader_config_handle_t` cleanup to the text fixture's `TearDown()`. --- test/loader/loader_config/urLoaderConfigCreate.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/loader/loader_config/urLoaderConfigCreate.cpp b/test/loader/loader_config/urLoaderConfigCreate.cpp index 442f6e41dc..df1293661b 100644 --- a/test/loader/loader_config/urLoaderConfigCreate.cpp +++ b/test/loader/loader_config/urLoaderConfigCreate.cpp @@ -5,12 +5,18 @@ #include "fixtures.hpp" -struct LoaderConfigCreateTest : ::testing::Test {}; +struct LoaderConfigCreateTest : ::testing::Test { + void TearDown() override { + if (loaderConfig) { + ASSERT_SUCCESS(urLoaderConfigRelease(loaderConfig)); + } + } -TEST_F(LoaderConfigCreateTest, Success) { ur_loader_config_handle_t loaderConfig = nullptr; +}; + +TEST_F(LoaderConfigCreateTest, Success) { ASSERT_SUCCESS(urLoaderConfigCreate(&loaderConfig)); - ASSERT_SUCCESS(urLoaderConfigRelease(loaderConfig)); } TEST_F(LoaderConfigCreateTest, InvalidNullPointerLoaderConfig) {