mirror of
https://github.com/monero-project/monero.git
synced 2026-07-30 23:50:24 -07:00
epee: avoid bad_weak_ptr during connection teardown
foreach_connection() can race with connection destruction while the protocol handler remains in the raw-pointer map. Use the non-throwing weak_from_this().lock() in add_ref() and treat expired connections as unavailable. This is an interim mitigation pending the broader connection lifetime fix in PR 7345.
This commit is contained in:
@@ -1219,16 +1219,13 @@ namespace net_utils
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
bool connection<T>::add_ref()
|
bool connection<T>::add_ref()
|
||||||
{
|
{
|
||||||
try {
|
auto self = connection<T>::weak_from_this().lock();
|
||||||
auto self = connection<T>::shared_from_this();
|
if (!self)
|
||||||
std::lock_guard<std::mutex> guard(m_state.lock);
|
|
||||||
this->self = std::move(self);
|
|
||||||
++m_state.protocol.reference_counter;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (boost::bad_weak_ptr &exception) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
std::lock_guard<std::mutex> guard(m_state.lock);
|
||||||
|
this->self = std::move(self);
|
||||||
|
++m_state.protocol.reference_counter;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
Reference in New Issue
Block a user