-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to fix lifetime of GlobalLogHandler #3221
base: main
Are you sure you want to change the base?
Try to fix lifetime of GlobalLogHandler #3221
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3221 +/- ##
==========================================
- Coverage 88.16% 88.15% -0.00%
==========================================
Files 198 198
Lines 6224 6236 +12
==========================================
+ Hits 5487 5497 +10
- Misses 737 739 +2
|
{ | ||
return GetHandlerAndLevel().first; | ||
if OPENTELEMETRY_UNLIKELY_CONDITION (GetHandlerAndLevel().destroyed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I interpret the standard correctly, this may be an undefined behavior.
[basic.life] says that "[t]he lifetime of an object o of type T ends when: <...> if T is a class type, the destructor call starts", and "after the lifetime of an object has ended and before the storage which the object occupied is reused or released, any pointer that represents the address of the storage location where the object will be or was located may be used but only in limited ways. <...> The program has undefined behavior if: <...> the pointer is used to access a non-static data member or call a non-static member function of the object".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a trick that the memory address of a static local variable will always be available in practice. So we can visit it even if it's destructed.
Fixes #3215
Changes
GlobalLogHandler
when callingOTEL_INTERNAL_LOG_*
.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes