Sunday, January 3, 2010

List push_back() function causes a crash

Most people while working with list iterators
are sure to have come across this problem
when working in C++ at some point in their lives.

Program crashes abruptly.

Debugging using the gdb debugger shows that
the crash occurs while executing the push_back()
function. I was using the Devshed C++ development
environment and noticing similar crashes with my
code. However, it turns out the problem did not have
anything to do with push_back() function. Rather,
it was happening because, appropriate memory management
was not being done for other allocated memory structs.
Typically, re-assignment of pointers which were not
appropriately free()'d before re-initialization was
resulting in these crashes. So as such push_back() is
not crashing but other poor memory management was
responsible. Please also check that you are not passing
a NULL as an argument for push_back(), which could
possibly cause a crash.


Post a Comment