C++ SEGMENT fault and vtable issues
Arthur Schwarz
aschwarz1309@att.net
Sun Oct 14 21:20:00 GMT 2012
Product Version = NetBeans IDE 7.2 (Build 201207171143)
Operating System = Windows 7 version 6.1 running on x86
Java; VM; Vendor = 1.7.0_03
Runtime = Java HotSpot(TM) Client VM 22.1-b02
Cygwin gcc 4.5.3
gdb 4.5.3
I have a problem with my C++ application. I have tried to find what is wrong in
my code and am unsuccessful, and amm hping that you can identify the issue.
The code fails (for different reasons) in two locations:
[code]
SlipHeader* oldHeader;
delete oldHeader; // SEGMENT fault; custom defined delete
SlipHeader* header;
stringstream pretty;
pretty << header->toString(); // call to pure virtual function
[/code]
The sequence of events is:
1: The first time through the code there is no exception.
2: The second time through the code there is an exception
In the first case, the address pointed to by oldHeader is within the range of
values which should not produce a segment fault. I do my own
allocation/dallocation. During allocation I get a block of memory. The address
pointed to is within the block. gdb doesn't provide any support in debugging so
I can't get any support other than the assumption that at the time the delete is
executed oldHeader points to or is the cause of the fault.
In the second instance I've looked at the vtable address and it is the same for
both the failed instance and the successfully executing instance.
I've looked at my code (step by naughty step) to try to find when the transition
from legitimate to illegitimate occurs and can not find any difference (to
warrant the errors).
So, does anyone have any thoughts as to what I might have done wrong and how to
find what I have done wrong? I've wored around the problem but I just know it's
going to pop up elsewhere - I'm writing regression tests and these errors just
popped up.
thanks
art
More information about the Gcc-help
mailing list