fix memory leak when ignoring test error/failure

This commit is contained in:
Günter Obiltschnig 2021-06-17 09:29:35 +02:00
parent 47e52f2d76
commit a9e7655569
2 changed files with 4 additions and 3 deletions

View File

@ -111,11 +111,11 @@ void TestCase::run(TestResult *result)
result->startTest(this); result->startTest(this);
setUp(); setUp();
try try
{ {
runTest(); runTest();
} }
catch (CppUnitException& e) catch (CppUnitException& e)
{ {
CppUnitException* copy = new CppUnitException(e); CppUnitException* copy = new CppUnitException(e);
result->addFailure(this, copy); result->addFailure(this, copy);
@ -126,7 +126,6 @@ void TestCase::run(TestResult *result)
msg.append(": "); msg.append(": ");
msg.append(e.what()); msg.append(e.what());
result->addError(this, new CppUnitException(msg)); result->addError(this, new CppUnitException(msg));
} }
catch (...) catch (...)
{ {

View File

@ -126,6 +126,7 @@ void TextTestResult::addError(Test* test, CppUnitException* e)
else else
{ {
_ostr << "ERROR (ignored)" << std::flush; _ostr << "ERROR (ignored)" << std::flush;
delete e;
} }
} }
@ -140,6 +141,7 @@ void TextTestResult::addFailure(Test* test, CppUnitException* e)
else else
{ {
_ostr << "FAILURE (ignored)" << std::flush; _ostr << "FAILURE (ignored)" << std::flush;
delete e;
} }
} }