could be because when u have erased the map node pointed to by iterMap,
iterMap++ crashes as the memory location pointed to by iterMap becomes
invalid.
so, instead of erasing in loop, do a clear () on map after the loop.
see inline.
hope this helps.
Sanjib Talukdar 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); ///////// Remove this line
}
>>> call this->colDtlsByName.clear ();
}
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.
--
Nothing will work if u don't.