Discussion:
Which destructor call is causing my program to crash?
(too old to reply)
Marcus P S
2009-02-12 07:54:56 UTC
Permalink
I have multiple instances of STL vectors of different classes in my
program, and I am getting a crash during the destructor call for one
of these objects -- the entire program executes without a problem down
to the last line in the code, and when the destructors get called, I
get a SIGABRT.

I have not been able to pinpoint which one of these destructor calls
is causing the SIGABRT. Looking at the back trace after the crash in
gdb, it is pretty clear it is inside a vector<...> destructor, but I
can't figure out for which object.

Does anyone have any suggestions how I might be able to do this?

Thanks,
Marcus
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Bart van Ingen Schenau
2009-02-13 07:18:54 UTC
Permalink
Post by Marcus P S
I have multiple instances of STL vectors of different classes in my
program, and I am getting a crash during the destructor call for one
of these objects -- the entire program executes without a problem down
to the last line in the code, and when the destructors get called, I
get a SIGABRT.
I have not been able to pinpoint which one of these destructor calls
is causing the SIGABRT. Looking at the back trace after the crash in
gdb, it is pretty clear it is inside a vector<...> destructor, but I
can't figure out for which object.
Does anyone have any suggestions how I might be able to do this?
First, make a copy of the program and store that in a secure location
(unless starting all over is a reasonable option).

Then, start stripping the program down. Take parts out and check if
stripping that part out caused the error to disappear. If not, leave it
out and take the next part out.
If taking out part A causes the error to disappear, take a critical look
at it to see if you see anything suspicious. If not, put the part *back
in* and take the next part out.

When you are down to a program of less than about 100 lines, and you
still don't have a clue what causes the problem, then post the code
here with a description of the error and the input you need to give (if
any).
Post by Marcus P S
Thanks,
Marcus
Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Danny.Wang
2009-02-13 07:49:24 UTC
Permalink
Post by Marcus P S
I have multiple instances of STL vectors of different classes in my
program, and I am getting a crash during the destructor call for one
of these objects -- the entire program executes without a problem down
to the last line in the code, and when the destructors get called, I
get a SIGABRT.
I have not been able to pinpoint which one of these destructor calls
is causing the SIGABRT. Looking at the back trace after the crash in
gdb, it is pretty clear it is inside a vector<...> destructor, but I
can't figure out for which object.
Does anyone have any suggestions how I might be able to do this?
{ signature and clc++m banner removed -mod }

maybe you should add some log in destructors of those different
classes.
hope it helps.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Thomas Richter
2009-02-13 18:18:47 UTC
Permalink
Post by Marcus P S
I have multiple instances of STL vectors of different classes in my
program, and I am getting a crash during the destructor call for one
of these objects -- the entire program executes without a problem down
to the last line in the code, and when the destructors get called, I
get a SIGABRT.
Try valgrind. Likely, something's screwed up already earlier.

So long,
Thomas
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Marcus P S
2009-02-14 11:08:07 UTC
Permalink
Thanks for the suggestions.

I tried logging information in my custom classes, but those did not
appear to be the problem (although I could not be 100% sure).

As backtraces for my g++ compiled code were not helpful, I tried the
Intel compiler, and then the gdb backtraces were more helpful. They
indicated that the problem was the destructor for a vector<double>
object. Digging a bit more, I found that the problem was that I was
overrunning the end of the vector by a single element, and this
corrupter the stl allocator information, and caused the SIGABRT during
the destructor.

I will have to try contacting some gdb experts to see if it is
possible to set breakpoints in destructors for cases when I do not
have the Intel compiler available.

Marcus
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Continue reading on narkive:
Loading...