Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54823 - trunk/libs/serialization/src
From: ramey_at_[hidden]
Date: 2009-07-08 19:09:30


Author: ramey
Date: 2009-07-08 19:09:29 EDT (Wed, 08 Jul 2009)
New Revision: 54823
URL: http://svn.boost.org/trac/boost/changeset/54823

Log:
Fix invalid pointer in unregister cast in void_cast.cpp - Again !!
Text files modified:
   trunk/libs/serialization/src/void_cast.cpp | 20 +++++++++++++++-----
   1 files changed, 15 insertions(+), 5 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-07-08 19:09:29 EDT (Wed, 08 Jul 2009)
@@ -224,21 +224,31 @@
     void_cast_detail::set_type::iterator it;
     for(it = s.begin(); it != s.end();){
         // note item 9 from Effective STL !!!
- if((*it)->m_base == m_base && m_derived == (*it)->m_derived
- && (
- (*it)->m_base_is_destroyed
+ if((*it)->m_base == m_base && m_derived == (*it)->m_derived){
+ // since recursion could invalidate it
+ const void_caster * vc = *it;
+ s.erase(it++);
+ if(vc->is_shortcut()){
+ // save pointer to set member
+ // and erase first
+ delete vc;
+ }
+ }
+ else
+ if( (*it)->m_base_is_destroyed
             || (*it)->m_derived_is_destroyed
             || *m_derived == *(*it)->m_base
             || *(*it)->m_derived == *m_base
- )){
+ ){
             // since recursion could invalidate it
             const void_caster * vc = *it;
- s.erase(it++);
+ s.erase(it);
             if(vc->is_shortcut()){
                 // save pointer to set member
                 // and erase first
                 delete vc;
             }
+ it = s.begin();
         }
         else
             it++;


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