|
From: Ioannis V. <iv...@em...> - 2003-07-15 18:00:26
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Shane Bryldt
> Sent: Friday, July 11, 2003 11:53 PM
> To: Hossein Haeri
> Cc: C++
> Subject: Re: [Dev-C++] STL Map question
>=20
>=20
> Each Channel contains 3 UserList's as well. =20
> First, depicts all
> users in the Channel, the second depicts all the operators of=20
> the channel,
> and the third depicts the priviledged users who are not=20
> operators.=20
These above 3 UserList contain the connected-at-the-time kinds of people =
or
are their contents "constant", that is updated by another way?
> 2) The=20
> User class is
> being deleted, without being removed from the UserList. =20
> However, I can find
> no indication of this in the code. The code is many=20
> thousands of lines, it
> is not a small project by any means. Providing the source=20
> for the issue,
> would require the entire project as the issue is not=20
> specifically a syntax
> issue, but rather a situational issue. I do believe something has
> invalidated a User class, which a UserList has a pointer to,=20
> and when trying
> to use it, is causing a segmentation fault. I'm sure most of=20
> the experts
> here will agree with my conclusion and realize tracing this=20
> problem is no
> easy task.
You can place a special debugging code, a loop that checks that the =
entries
in all UserLists are consistent. An example is to sum up the sizes of =
each
map with the global to see where the problem is.
Then add a loop to verify each user using operator[]. Where you get as a
return value the pointer value 0 and in the UserList (which will be the =
one
that crashes) you get a pointer value then you have found the problem.
So make the above in a verify function which will be executed after =
every
complete entry update and which will be in the pseudocode-style:
// Assuming UserList is a typedef of a map
// and the UserList that crashes is the global
// because I do not remember.
void verify(const UserList &global, const UserList &whatever1, // etc)
{
=20
using namespace std;
UserList ::size_type sum=3Dwhatever1.size()+whatever.size()+//etc ;
if(sum!=3Dglobal.size())
{
for(UserList::const_iterator p=3Dglobal.begin(); p!=3Dglobal.end(); =
++p)
{
if(whatever1[p->first]+whatever2[p->first]+.... =3D=3D 0)
{
std::cerr<<"\n\nThe corrupted record is "<<p->first<<endl<<endl;
system("pause");
}
}
}
else cout<<"\n\nVerification phase passed\n\n";
}
=20
=20
>=20
> I've considered some commercial products like Purify, or some=20
> other memory
> tracking products, but I have no experience with any, since=20
> I've never had
> an issue I couldn't resolve purely with GDB. Since the=20
> problem traces back
> most likely to an invalid pointer reference, does anyone have=20
> suggestions on
> how I could possibly detect where the pointer is being deleted? I've
> considered the idea of using smart pointers to track the=20
> issue down, but
> again I'm not entirely certain of how to implement some code=20
> to track where
> the User is being deleted without being removed from the=20
> channels they are
> in... It could also potentially be an issue with overwritting=20
> memory, but
> with how often it is caused in exactly the same way, it's=20
> unlikely to be
> memory overbounding.
> I noticed a location where the key being used was being changed (a
> nickname), and in those cases, where the old code would just=20
> rename the
> nickname, I have now remove from the map and then readd to=20
> the map. When it
> tries to remove from the map is when it crashes. I can only=20
> assume that the
> problem is an invalid pointer, thus the map::find function is crashing
> because of invalid memory.=20
Do you check the result of map::find against map::end()?
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|