Re: Problem with Map Iterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As far as I know, map::erase invalidates the iterator, so incrementing
the iterator after erasing it is invalid.

On 5/15/06, Sanjib Talukdar <sanjibt@xxxxxxxxxxxx> wrote:
Hi,

I am getting a segmentation fault error while executing the following
code:

        if (!this->colDtlsByName.empty())
        {
             std::map< std::string, CS_DATAFMT*,
             std::less<std::string> >::iterator iterMap;
            for (iterMap = this->colDtlsByName.begin();
                iterMap != this->colDtlsByName.end(); ++iterMap)
           {
               CS_DATAFMT* obj = iterMap->second;
               if (obj != NULL)
                     delete obj;
               this->colDtlsByName.erase(iterMap);
           }
        }

The backtrace from gdb is as follows:

        #0  0xff0e29b4 in std::_Rb_tree_increment () from
/usr/sfw/lib/libstdc++.so.6
        #1  0x0009854c in std::_Rb_tree_iterator<std::pair<std::string
const, _cs_datafmt*> >::operator++ (this=0xfe77a0c4) at stl_tree.h:180
        #2  0x0005a84c in MACDBQueryHandler::clearColInfo
(this=0xfe77bd30, inType=ALL)
            at MACDBQueryHandler.C:123

The above code is in the method MACDBQueryHandler::clearColInfo() which
is being invoked in the class destructor.
We are using gcc version 3.4.3 on Solaris 10. The library libstdc++.so.6
is pointing to libstdc++.so.6.0.3.

Can anyone please point out the reason for the error?
Thank You.
Sanjib.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux