diff --git a/src/messages/data.hpp b/src/messages/data.hpp index 4bcd189fd5..c69e6e178d 100644 --- a/src/messages/data.hpp +++ b/src/messages/data.hpp @@ -61,6 +61,7 @@ template public: typedef pool type; typedef boost::shared_ptr ptr; + typedef boost::weak_ptr weak_ptr; typedef typename element_type::ptr element_ptr; typedef boost::function callback_type; @@ -149,6 +150,7 @@ class data { public: typedef boost::intrusive_ptr ptr; typedef pool::ptr pool_ptr; + typedef pool::weak_ptr pool_weak_ptr; data(pool_ptr p, size_t s); @@ -210,7 +212,14 @@ private: if (count == 1 && s->m_live) { // recycle if endpoint exists s->m_live = false; - s->m_pool->recycle(ptr(const_cast(s))); + + + pool_ptr pp = s->m_pool.lock(); + if (pp) { + pp->recycle(ptr(const_cast(s))); + } + + //s->m_pool->recycle(ptr(const_cast(s))); } else if (count == 0) { boost::checked_delete(static_cast(s)); } @@ -235,7 +244,7 @@ private: // reference counting size_t m_index; mutable boost::detail::atomic_count m_ref_count; - mutable pool_ptr m_pool; + mutable pool_weak_ptr m_pool; mutable bool m_live; };