-
Notifications
You must be signed in to change notification settings - Fork 494
[SDK] Use shared_ptr internally for AttributesProcessor to prevent use-after-free #3457
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
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
Thanks for raising the PR. Could you add a dedicated test to validate the seg fault? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3457 +/- ##
==========================================
+ Coverage 89.88% 89.89% +0.02%
==========================================
Files 212 212
Lines 6941 6942 +1
==========================================
+ Hits 6238 6240 +2
+ Misses 703 702 -1
🚀 New features to boost your workflow:
|
done |
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.
LGTM
Fixes #3456
Changes
This PR changes metric storage and View class to use
std::shared_ptr<const AttributesProcessor>
internally, while the public View API continues to accept astd::unique_ptr
. The unique pointer is promoted to a shared pointer inside the View constructor. The change prevents use-after-free when metrics are recorded afterMeterProvider
shutdown or destruction.Each metric recording operation now accesses the
AttributesProcessor
via astd::shared_ptr
instead of a raw pointer as before. This adds a minimal overhead due to shared pointer reference counting in recording hot-path, but ensures memory safety, so should be acceptable.For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes