|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58020 - trunk/libs/serialization/src
From: ramey_at_[hidden]
Date: 2009-11-28 17:18:00
Author: ramey
Date: 2009-11-28 17:18:00 EST (Sat, 28 Nov 2009)
New Revision: 58020
URL: http://svn.boost.org/trac/boost/changeset/58020
Log:
Fix memory leaks in void_caster short cut memory leaks
Text files modified:
trunk/libs/serialization/src/void_cast.cpp | 76 ++++++++++++++++++++++++---------------
1 files changed, 47 insertions(+), 29 deletions(-)
Modified: trunk/libs/serialization/src/void_cast.cpp
==============================================================================
--- trunk/libs/serialization/src/void_cast.cpp (original)
+++ trunk/libs/serialization/src/void_cast.cpp 2009-11-28 17:18:00 EST (Sat, 28 Nov 2009)
@@ -113,7 +113,7 @@
{
recursive_register(includes_virtual_base);
}
- ~void_caster_shortcut(){
+ virtual ~void_caster_shortcut(){
recursive_unregister();
}
};
@@ -199,7 +199,7 @@
) :
void_caster(derived, base)
{}
- ~void_caster_argument(){};
+ virtual ~void_caster_argument(){};
};
#ifdef BOOST_MSVC
@@ -220,27 +220,47 @@
std::clog << "\n";
#endif
- s.insert(this);
+ std::pair<void_cast_detail::set_type::const_iterator, bool> result;
+ result = s.insert(this);
+ assert(result.second);
// generate all implied void_casts.
void_cast_detail::set_type::const_iterator it;
for(it = s.begin(); it != s.end(); ++it){
- if(* m_derived == * (*it)->m_base)
- new void_caster_shortcut(
+ if(* m_derived == * (*it)->m_base){
+ const void_caster_argument vca(
(*it)->m_derived,
- m_base,
- m_difference + (*it)->m_difference,
- includes_virtual_base,
- this
+ m_base
);
- if(* (*it)->m_derived == * m_base)
- new void_caster_shortcut(
- m_derived,
- (*it)->m_base,
- m_difference + (*it)->m_difference,
- includes_virtual_base,
- this
+ void_cast_detail::set_type::const_iterator i;
+ i = s.find(& vca);
+ if(i == s.end()){
+ new void_caster_shortcut(
+ (*it)->m_derived,
+ m_base,
+ m_difference + (*it)->m_difference,
+ includes_virtual_base,
+ this
+ );
+ }
+ }
+ if(* (*it)->m_derived == * m_base){
+ const void_caster_argument vca(
+ (*it)->m_derived,
+ m_base
);
+ void_cast_detail::set_type::const_iterator i;
+ i = s.find(& vca);
+ if(i == s.end()){
+ new void_caster_shortcut(
+ m_derived,
+ (*it)->m_base,
+ m_difference + (*it)->m_difference,
+ includes_virtual_base,
+ this
+ );
+ }
+ }
}
}
@@ -249,25 +269,23 @@
if(void_caster_registry::is_destroyed())
return;
+ #ifdef BOOST_SERIALIZATION_LOG
+ std::clog << "recursive_unregister\n";
+ std::clog << m_derived->get_debug_info();
+ std::clog << "<-";
+ std::clog << m_base->get_debug_info();
+ std::clog << "\n";
+ #endif
+
void_cast_detail::set_type & s
= void_caster_registry::get_mutable_instance();
// delete all shortcuts which use this primitive
void_cast_detail::set_type::iterator it;
for(it = s.begin(); it != s.end();){
- if(
- m_base == (*it)->m_base
- && m_derived == (*it)->m_derived
- ){
- s.erase(it++);
- }
- else
- if( (*it)->m_parent == this ){
- // since recursion could invalidate it
- // save pointer to set member
- const void_caster * vc = *it;
- // and erase first
- s.erase(it++);
+ const void_caster * vc = *it;
+ if(vc->m_parent == this){
+ s.erase(it);
delete vc;
it = s.begin();
}
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