summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-08 13:18:44 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-12 09:08:12 +0200
commitfe4794f70ecc4a302b22ad26614203a70c049a13 (patch)
treeba36bdd9e2c00ddb110f82905dd883a982c510cd /src/testlib
parentd2ae13b75beb29f42a98589a374ec92f9b382f9d (diff)
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>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qabstractitemmodeltester.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/testlib/qabstractitemmodeltester.cpp b/src/testlib/qabstractitemmodeltester.cpp
index a09d007a82..4c86d65e77 100644
--- a/src/testlib/qabstractitemmodeltester.cpp
+++ b/src/testlib/qabstractitemmodeltester.cpp
@@ -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;
}