refactor: Use aliasing shared_ptr in Sock::Wait
What changed, and why it matters
This is a small internal code cleanup in Bitcoin Core's socket helper class. It changes how a temporary shared pointer is created so that it refers to an existing socket object without taking ownership of it. There is no user-facing behavior change and no security fix.
No security action needed. Treat as a normal code-quality refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors Sock::Wait() in src/util/sock.cpp. Previously it constructed a std::shared_ptr
Changed components
src/util/sock.cppSock::WaitInspect captured patch +5 / −3
diff --git a/src/util/sock.cpp b/src/util/sock.cpp
index ba822a0e..752fb327 100644
--- a/src/util/sock.cpp
+++ b/src/util/sock.cpp
@@ -138,10 +138,12 @@ bool Sock::IsSelectable() const
bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
{
- // We need a `shared_ptr` owning `this` for `WaitMany()`, but don't want
+ // We need a `shared_ptr` holding `this` for `WaitMany()`, but don't want
// `this` to be destroyed when the `shared_ptr` goes out of scope at the
- // end of this function. Create it with a custom noop deleter.
- std::shared_ptr<const Sock> shared{this, [](const Sock*) {}};
+ // end of this function.
+ // Create it with an aliasing shared_ptr that points to `this` without
+ // owning it.
+ std::shared_ptr<const Sock> shared{std::shared_ptr<const Sock>{}, this};
EventsPerSock events_per_sock{std::make_pair(shared, Events{requested})};
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.