[Bug libstdc++/27530] Possible memory leak in std::vector<int>::reserve() or std::vector<int>::clear()

ksharenkov at ya dot ru gcc-bugzilla@gcc.gnu.org
Wed Aug 2 03:47:00 GMT 2006

------- Comment #7 from ksharenkov at ya dot ru  2006-08-02 03:47 -------

Now I can say more about this problem. before code listing
I am sure that problem in template instantiation.
code if CBaseSeat::CBaseSeat() id used deeply in templates 
holder<T1> contains T1 which contains of vector<Derived from BaseSeat> which
contains vector<int>

there are facts:
1) The leak was gone just i removed line    
m_cardsSet.reserve( MAX_CARDS_ON_HAND );
it was need only for allocatio optimize

2) Windows version of this code not affected by this problem

In any case i will try to create self contained test code when i will have a
day for it. But it will be rather big i think.

There is the code:
CMessage* CMessage::clone() const
    CMessage* result = new CMessage( m_descriptor, m_session, m_id );
    std::stringstream buffer;

    this->write( buffer );

    // read unnecessary type
    short type;
    shortSerializer.read( buffer, type );
    result->read( buffer );

    return result;

CMessage* CMessageFactory::createInstance( CSession* sess, MessageType type )
    Descriptors::iterator pos = m_descriptors.find( type );
    if( pos==m_descriptors.end() )
        throw std::logic_error("ERROR: Trying create message of unknown type"

    CMessage* result = new CMessage( pos->second, sess, nextMessageId() );

    return result;



More information about the Gcc-bugs mailing list