Close memory leak in QTestLib support for item model testing

QTest::toString allocates memory by calling qstrdup; that memory must
be freed by the caller.

Change-Id: I218bc57b3312fdd9195fb49eaed7d20df4bf717c
Fixes: QTBUG-84081
Coverity-Id: 186979
Covierty-Id: 186980
Pick-to: 5.15
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-05-08 13:18:44 +02:00
parent d2ae13b75b
commit fe4794f70e

View File

@ -819,13 +819,23 @@ bool QAbstractItemModelTesterPrivate::compare(const T1 &t1, const T2 &t2,
break;
case QAbstractItemModelTester::FailureReportingMode::Warning:
if (!result)
qCWarning(lcModelTest, formatString, actual, QTest::toString(t1), expected, QTest::toString(t2), file, line);
if (!result) {
auto t1string = QTest::toString(t1);
auto t2string = QTest::toString(t2);
qCWarning(lcModelTest, formatString, actual, t1string, expected, t2string, file, line);
delete [] t1string;
delete [] t2string;
}
break;
case QAbstractItemModelTester::FailureReportingMode::Fatal:
if (!result)
qFatal(formatString, actual, QTest::toString(t1), expected, QTest::toString(t2), file, line);
if (!result) {
auto t1string = QTest::toString(t1);
auto t2string = QTest::toString(t2);
qFatal(formatString, actual, t1string, expected, t2string, file, line);
delete [] t1string;
delete [] t2string;
}
break;
}