Actually, my real question is: is there anything wrong with the indicated line in the following code ("Causes SIGABRT"):
char* myFunc(char *param) {
char* leaked = new char[80]; // Intentionally leaked
if (param == NULL) throw logic_error("Parameter was null!"); // Causes SIGABRT
strcpy(leaked, param);
// Missing return, but never gets this far, so should be okay.
}
void test_non_happy_myFunc()
{
try {
myFunc(NULL);
} catch (logic_error&) {
cout << "Test succeeded!" << endl;
return;
}
cout << "Test FAILED!" << endl;
}
int main()
{
test_non_happy_myFunc();
}
I'm trying to come up with a minimal test case to send to IBM/Rational to prove that there's an issue with their purify software, so I'm running it by the S.O. community first. Yes, I'm intentionally leaking memory on the 2nd line, and yes, I know the pointer "leaked" is unitialized when the exception is thrown.
The above code runs normally outside of purify when compiled with g++, but causes a core dump when run inside of purify. Did I make a rookie mistake in the above code (making the SIGABRT my fault), or can I point the finger at IBM/Rational Purify?
Edit: (clarifications)
Run on the command line without purify, the above complete program prints:
Test succeeded!
Run inside of purify, purify reports:
COR: Fatal core dump
This is occurring while in thread 1299:
_p450static [rtlib.o]
abort [libc.so.6]
uw_init_context_1 [unwind-dw2.c:1256]
_Unwind_RaiseException [unwind.inc:88]
__cxa_throw [eh_throw.cc:78]
myFunc(char*) [exception_test.cc:9]
test_non_happy_myFunc() [exception_test.cc:17]
main [exception_test.cc:28]
Note that after prerequisite includes and such, line 9 winds up being the line I indicated.