Commit 655b3f6f authored by Dominik Charousset's avatar Dominik Charousset

Fix leak with weak ptr after latest optimization

parent 3a24d16d
...@@ -71,7 +71,7 @@ class actor_proxy : public abstract_actor { ...@@ -71,7 +71,7 @@ class actor_proxy : public abstract_actor {
* Tries to expire this anchor. Fails if reference * Tries to expire this anchor. Fails if reference
* count of the proxy is nonzero. * count of the proxy is nonzero.
*/ */
bool try_expire(size_t) noexcept; bool try_expire() noexcept;
std::atomic<actor_proxy*> m_ptr; std::atomic<actor_proxy*> m_ptr;
detail::shared_spinlock m_lock; detail::shared_spinlock m_lock;
}; };
......
...@@ -55,10 +55,10 @@ actor_proxy_ptr actor_proxy::anchor::get() { ...@@ -55,10 +55,10 @@ actor_proxy_ptr actor_proxy::anchor::get() {
return result; return result;
} }
bool actor_proxy::anchor::try_expire(size_t expected_rc) noexcept { bool actor_proxy::anchor::try_expire() noexcept {
std::lock_guard<detail::shared_spinlock> guard{m_lock}; std::lock_guard<detail::shared_spinlock> guard{m_lock};
// double-check reference count // double-check reference count
if (m_ptr.load()->get_reference_count() == expected_rc) { if (m_ptr.load()->get_reference_count() == 0) {
m_ptr = nullptr; m_ptr = nullptr;
return true; return true;
} }
...@@ -76,7 +76,12 @@ actor_proxy::actor_proxy(actor_id aid, node_id nid) ...@@ -76,7 +76,12 @@ actor_proxy::actor_proxy(actor_id aid, node_id nid)
} }
void actor_proxy::request_deletion(bool decremented_rc) noexcept { void actor_proxy::request_deletion(bool decremented_rc) noexcept {
if (m_anchor->try_expire(decremented_rc ? 0 : 1)) { // make sure ref count is 0 because try_expire might leak otherwise
if (!decremented_rc && m_rc.fetch_sub(1, std::memory_order_acq_rel) != 1) {
// deletion request canceled due to a weak ptr access
return;
}
if (m_anchor->try_expire()) {
delete this; delete this;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment