Skip to content

Commit e02d1c5

Browse files
committed
Fix memory leak issue in test
1 parent 4aadb2a commit e02d1c5

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

sdk/test/trace/tracer_config_test.cc

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,43 @@ std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeVal
3636
std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue> attr3 = {
3737
"accept_third_attr", 3};
3838

39-
const instrumentation_scope::InstrumentationScope instrumentation_scopes[] = {
40-
*instrumentation_scope::InstrumentationScope::Create("test_scope_1").get(),
41-
*instrumentation_scope::InstrumentationScope::Create("test_scope_2", "1.0").get(),
42-
*instrumentation_scope::InstrumentationScope::Create("test_scope_3",
43-
"0",
44-
"https://opentelemetry.io/schemas/v1.18.0")
45-
.get(),
46-
*instrumentation_scope::InstrumentationScope::Create("test_scope_3",
47-
"0",
48-
"https://opentelemetry.io/schemas/v1.18.0",
49-
{attr1})
50-
.get(),
51-
*instrumentation_scope::InstrumentationScope::Create("test_scope_4",
52-
"0",
53-
"https://opentelemetry.io/schemas/v1.18.0",
54-
{attr1, attr2, attr3})
55-
.get(),
39+
const std::array<instrumentation_scope::InstrumentationScope *, 5> instrumentation_scopes = {
40+
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_1")).get(),
41+
std::move(instrumentation_scope::InstrumentationScope::Create("test_scope_2", "1.0")).get(),
42+
std::move(instrumentation_scope::InstrumentationScope::Create(
43+
"test_scope_3",
44+
"0",
45+
"https://opentelemetry.io/schemas/v1.18.0"))
46+
.get(),
47+
std::move(instrumentation_scope::InstrumentationScope::Create(
48+
"test_scope_3",
49+
"0",
50+
"https://opentelemetry.io/schemas/v1.18.0",
51+
{attr1}))
52+
.get(),
53+
std::move(instrumentation_scope::InstrumentationScope::Create(
54+
"test_scope_4",
55+
"0",
56+
"https://opentelemetry.io/schemas/v1.18.0",
57+
{attr1, attr2, attr3}))
58+
.get(),
5659
};
5760

5861
// Test fixture for VerifyDefaultConfiguratorBehavior
5962
class DefaultTracerConfiguratorTestFixture
60-
: public ::testing::TestWithParam<instrumentation_scope::InstrumentationScope>
63+
: public ::testing::TestWithParam<instrumentation_scope::InstrumentationScope *>
6164
{};
6265

6366
// verifies that the default configurator always returns the default tracer config
6467
TEST_P(DefaultTracerConfiguratorTestFixture, VerifyDefaultConfiguratorBehavior)
6568
{
66-
const instrumentation_scope::InstrumentationScope &scope = GetParam();
69+
instrumentation_scope::InstrumentationScope *scope = GetParam();
6770
trace_sdk::TracerConfigurator default_configurator =
6871
trace_sdk::TracerConfig::DefaultConfigurator();
6972

70-
ASSERT_EQ(default_configurator(scope), trace_sdk::TracerConfig::Default());
73+
ASSERT_EQ(default_configurator(*scope), trace_sdk::TracerConfig::Default());
7174
}
7275

7376
INSTANTIATE_TEST_SUITE_P(InstrumentationScopes,
7477
DefaultTracerConfiguratorTestFixture,
75-
::testing::ValuesIn(instrumentation_scopes));
78+
::testing::ValuesIn(instrumentation_scopes));

0 commit comments

Comments
 (0)