Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class ETWProvider
auto &data = it->second;
unsigned long result = STATUS_OK;

if (data.refCount == 0)
{
return STATUS_ERROR;
}

data.refCount--;
if (data.refCount == 0)
{
Expand All @@ -232,6 +237,7 @@ class ETWProvider
}
return result;
}
++it;
}
return STATUS_ERROR;
}
Expand Down
14 changes: 14 additions & 0 deletions exporters/etw/test/etw_provider_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,18 @@ TEST(ETWProvider, CheckCloseSuccess)
ASSERT_FALSE(etw.is_registered(providerName));
}

TEST(ETWProvider, CheckCloseInfiniteLoop)
{
std::string providerName1 = "Provider1";
std::string providerName2 = "Provider2";

static ETWProvider etw;
auto handle1 = etw.open(providerName1.c_str());
auto handle2 = etw.open(providerName2.c_str());

// This should not hang
etw.close(handle2);
etw.close(handle1);
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should include assertions to verify that the close operations succeeded. Currently, the test only verifies that it doesn't hang, but doesn't check if the operations completed successfully. Consider adding assertions to check the return values and provider registration status.

Copilot uses AI. Check for mistakes.
}
Comment on lines +64 to +94
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't cover the refCount underflow scenario mentioned in the issue. The fix added a check at lines 213-216 to prevent underflow when close is called too many times on the same handle, but this behavior is not tested. Consider adding a test case that calls close multiple times on the same handle and verifies it returns STATUS_ERROR on subsequent calls.

Copilot uses AI. Check for mistakes.

#endif
Loading