Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Policy-Refactor: Memory Leak in Pool #53

Closed
megabyte1024 opened this issue Jan 20, 2012 · 0 comments
Closed

Policy-Refactor: Memory Leak in Pool #53

megabyte1024 opened this issue Jan 20, 2012 · 0 comments

Comments

@megabyte1024
Copy link

file: data.hpp
issue description: There is a memory leak in the pool class due to a cyclic dependency between the pool and the data classes.
fix:

diff --git a/src/messages/data.hpp b/src/messages/data.hpp
--- a/src/messages/data.hpp
+++ b/src/messages/data.hpp
@@ -61,6 +61,7 @@ template
public:
typedef pool<element_type> type;
typedef boost::shared_ptr ptr;

  •   typedef boost::weak_ptr<type> ptr_weak;
    
    typedef typename element_type::ptr element_ptr;
    typedef boost::function<void()> callback_type;

@@ -149,6 +150,7 @@ class data {
public:
typedef boost::intrusive_ptr ptr;
typedef pool::ptr pool_ptr;

  •   typedef pool<data>::ptr_weak pool_weak_ptr;
    

    data(pool_ptr p, size_t s);

@@ -210,7 +212,10 @@ private:
if (count == 1 && s->m_live) {
// recycle if endpoint exists
s->m_live = false;

  •        s->m_pool->recycle(ptr(const_cast<data *>(s)));
    
  •                   pool_ptr pp = s->m_pool.lock();
    
  •                   if (pp != NULL) {
    
  •                       pp->recycle(ptr(const_cast<data *>(s)));
    
  •                   }
     } else if (count == 0) {
         boost::checked_delete(static_cast<data const *>(s));
     }
    
    @@ -235,7 +240,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;
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant