Skip to content

Commit

Permalink
[coverity] Fix 1566354 Resource leak
Browse files Browse the repository at this point in the history
In the `test-platform` conformance test suite, 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()`.
  • Loading branch information
kbenzie committed Jul 19, 2023
1 parent 5230505 commit 656361b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/conformance/platform/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ struct urTest : ::testing::Test {

void SetUp() override {
ur_device_init_flags_t device_flags = 0;
ur_loader_config_handle_t config;
ASSERT_SUCCESS(urLoaderConfigCreate(&config));
ASSERT_SUCCESS(
urLoaderConfigEnableLayer(config, "UR_LAYER_FULL_VALIDATION"));
ASSERT_SUCCESS(urInit(device_flags, config));
ASSERT_SUCCESS(urLoaderConfigRelease(config));
ASSERT_SUCCESS(urLoaderConfigCreate(&loader_config));
ASSERT_SUCCESS(urLoaderConfigEnableLayer(loader_config,
"UR_LAYER_FULL_VALIDATION"));
ASSERT_SUCCESS(urInit(device_flags, loader_config));

uint32_t adapter_count;
ASSERT_SUCCESS(urAdapterGet(0, nullptr, &adapter_count));
Expand All @@ -31,10 +29,14 @@ struct urTest : ::testing::Test {
for (auto adapter : adapters) {
ASSERT_SUCCESS(urAdapterRelease(adapter));
}
if (loader_config) {
ASSERT_SUCCESS(urLoaderConfigRelease(loader_config));
}
ur_tear_down_params_t tear_down_params{};
ASSERT_SUCCESS(urTearDown(&tear_down_params));
}

ur_loader_config_handle_t loader_config = nullptr;
std::vector<ur_adapter_handle_t> adapters;
};

Expand Down

0 comments on commit 656361b

Please sign in to comment.