Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85250 - in trunk: boost/heap/detail libs/heap/test
From: tim_at_[hidden]
Date: 2013-08-09 05:18:27


Author: timblechmann
Date: 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013)
New Revision: 85250
URL: http://svn.boost.org/trac/boost/changeset/85250

Log:
heap: fix memory leak in destructor

fixes #8977

Text files modified:
   trunk/boost/heap/detail/heap_node.hpp | 7 +++++++
   trunk/libs/heap/test/binomial_heap_test.cpp | 6 ++++++
   trunk/libs/heap/test/common_heap_tests.hpp | 9 +++++++++
   trunk/libs/heap/test/d_ary_heap_test.cpp | 7 +++++++
   trunk/libs/heap/test/fibonacci_heap_test.cpp | 7 +++++++
   trunk/libs/heap/test/pairing_heap_tests.cpp | 7 +++++++
   trunk/libs/heap/test/priority_queue_test.cpp | 6 ++++++
   trunk/libs/heap/test/skew_heap_test.cpp | 7 +++++++
   8 files changed, 56 insertions(+), 0 deletions(-)

Modified: trunk/boost/heap/detail/heap_node.hpp
==============================================================================
--- trunk/boost/heap/detail/heap_node.hpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/boost/heap/detail/heap_node.hpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -142,6 +142,7 @@
     {
         node_pointer n = static_cast<node_pointer>(base);
         n->clear_subtree(alloc_);
+ n->~Node();
         alloc_.deallocate(n, 1);
     }
 
@@ -194,6 +195,8 @@
         children.clone_from(rhs.children, node_cloner<heap_node, node_base, Alloc>(allocator), nop_disposer());
     }
 
+ ~heap_node(){}
+
     size_type child_count(void) const
     {
         BOOST_STATIC_ASSERT(constant_time_child_size);
@@ -237,6 +240,8 @@
     {}
 #endif
 
+ ~parent_pointing_heap_node() {}
+
     template <typename Alloc>
     struct node_cloner
     {
@@ -310,6 +315,8 @@
         super_t(v), mark(false)
     {}
 
+ ~marked_heap_node() {}
+
 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
     template <class... Args>
     marked_heap_node(Args&&... args):

Modified: trunk/libs/heap/test/binomial_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/binomial_heap_test.cpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/libs/heap/test/binomial_heap_test.cpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -68,3 +68,9 @@
                                        boost::heap::allocator<std::allocator<int> > > pri_queue;
     run_common_heap_tests<pri_queue>();
 }
+
+BOOST_AUTO_TEST_CASE( binomial_heap_leak_test )
+{
+ typedef boost::heap::binomial_heap<boost::shared_ptr<int> > pri_queue;
+ run_leak_check_test<pri_queue>();
+}

Modified: trunk/libs/heap/test/common_heap_tests.hpp
==============================================================================
--- trunk/libs/heap/test/common_heap_tests.hpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/libs/heap/test/common_heap_tests.hpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -14,6 +14,7 @@
 
 #include <boost/concept/assert.hpp>
 #include <boost/concept_archetype.hpp>
+#include <boost/shared_ptr.hpp>
 
 #include <boost/heap/heap_concepts.hpp>
 
@@ -440,6 +441,14 @@
     check_q(q, data);
 }
 
+template <typename pri_queue>
+void run_leak_check_test(void)
+{
+ pri_queue q;
+ q.push(boost::shared_ptr<int>(new int(0)));
+}
+
+
 struct less_with_T
 {
     typedef int T;

Modified: trunk/libs/heap/test/d_ary_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/d_ary_heap_test.cpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/libs/heap/test/d_ary_heap_test.cpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -126,3 +126,10 @@
                                     boost::heap::allocator<std::allocator<int> > > pri_queue;
     run_common_heap_tests<pri_queue>();
 }
+
+
+BOOST_AUTO_TEST_CASE( d_ary_heap_leak_test )
+{
+ typedef boost::heap::d_ary_heap<boost::shared_ptr<int>, boost::heap::arity<2> > pri_queue;
+ run_leak_check_test<pri_queue>();
+}

Modified: trunk/libs/heap/test/fibonacci_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/fibonacci_heap_test.cpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/libs/heap/test/fibonacci_heap_test.cpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -72,3 +72,10 @@
                                        boost::heap::allocator<std::allocator<int> > > pri_queue;
     run_common_heap_tests<pri_queue>();
 }
+
+
+BOOST_AUTO_TEST_CASE( fibonacci_heap_leak_test )
+{
+ typedef boost::heap::fibonacci_heap<boost::shared_ptr<int> > pri_queue;
+ run_leak_check_test<pri_queue>();
+}

Modified: trunk/libs/heap/test/pairing_heap_tests.cpp
==============================================================================
--- trunk/libs/heap/test/pairing_heap_tests.cpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/libs/heap/test/pairing_heap_tests.cpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -70,3 +70,10 @@
                                       boost::heap::allocator<std::allocator<int> > > pri_queue;
     run_common_heap_tests<pri_queue>();
 }
+
+
+BOOST_AUTO_TEST_CASE( pairing_heap_leak_test )
+{
+ typedef boost::heap::pairing_heap<boost::shared_ptr<int> > pri_queue;
+ run_leak_check_test<pri_queue>();
+}

Modified: trunk/libs/heap/test/priority_queue_test.cpp
==============================================================================
--- trunk/libs/heap/test/priority_queue_test.cpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/libs/heap/test/priority_queue_test.cpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -41,3 +41,9 @@
     run_common_priority_queue_tests<false>();
     run_common_priority_queue_tests<true>();
 }
+
+BOOST_AUTO_TEST_CASE( std_pri_queue_leak_test )
+{
+ typedef boost::heap::priority_queue<boost::shared_ptr<int> > pri_queue;
+ run_leak_check_test<pri_queue>();
+}

Modified: trunk/libs/heap/test/skew_heap_test.cpp
==============================================================================
--- trunk/libs/heap/test/skew_heap_test.cpp Fri Aug 9 04:15:45 2013 (r85249)
+++ trunk/libs/heap/test/skew_heap_test.cpp 2013-08-09 05:18:27 EDT (Fri, 09 Aug 2013) (r85250)
@@ -116,3 +116,10 @@
                                    boost::heap::allocator<std::allocator<int> > > pri_queue;
     run_common_heap_tests<pri_queue>();
 }
+
+
+BOOST_AUTO_TEST_CASE( skew_heap_leak_test )
+{
+ typedef boost::heap::skew_heap<boost::shared_ptr<int> > pri_queue;
+ run_leak_check_test<pri_queue>();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk