clean(libsinsp): do not abuse std::shared_ptr for creating table entries #2747
Conversation
Perf diff from master - unit testsHeap diff from master - unit testsHeap diff from master - scap fileBenchmarks diff from master |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2747 +/- ##
==========================================
+ Coverage 74.56% 74.57% +0.01%
==========================================
Files 292 292
Lines 29998 30025 +27
Branches 4651 4657 +6
==========================================
+ Hits 22367 22392 +25
- Misses 7631 7633 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4720a72 to
37468d2
Compare
|
LGTM label has been added. DetailsGit tree hash: ebed78d47eaaf76c4647823cb0cbabed5fa8b03b |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ekoops, irozzo-1A The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
| return static_cast<ss_plugin_table_entry_t*>(owned_ptr); | ||
| // Store shared_ptr for lifetime management, return raw pointer | ||
| owner->store_accessed_entry(ret); | ||
| return static_cast<ss_plugin_table_entry_t*>(ret.get()); |
There was a problem hiding this comment.
Just double checking, because I'm a little bit on thin ice here, but is it safe to use ret.get() after doing std:move(ret) in store_accessed_entry() or is something like this needed:
auto raw_ptr = ret.get();
owner->store_accessed_entry(ret);
return static_cast<ss_plugin_table_entry_t*>(raw_ptr);
There was a problem hiding this comment.
Hey @terror96 . Basically the std::move(entry) you see inside store_accessed_entry() acts on a copy of this shared pointer. So we are moving the copy there, not the original ret.
There was a problem hiding this comment.
yep, if stored_accessed_entry() would have taken a ref we would have a problem here
Add a separate storage for created table entries using std::unique_ptr to make the ownership semantic clearer. This removes the hacky usage of no-op deleter with std::shared_ptr. Signed-off-by: irozzo-1A <iacopo@sysdig.com>
37468d2 to
f1eade0
Compare
What type of PR is this?
/kind cleanup
Any specific area of the project related to this PR?
/area libsinsp
Does this PR require a change in the driver versions?
What this PR does / why we need it:
Add a separate container for created table entries using std::unique_ptr to make the ownership semantic clearer. This removes the hacky usage of no-op deleter with std::shared_ptr.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: