From a094bf5a893c3cccffff10c1420bfbe3a3c02a7c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 3 Jan 2013 15:17:21 -0200 Subject: Don't increase the reference count if dynamic_cast failed If the dynamic_cast failed in QSharedPointer::dynamicCast or qSharedPointerDynamicCast, we should avoid creating the QSharedPointer that shares the weak and strong reference counts. In Qt 5, this does not imply a leak since the original pointer is stored internally for deletion. In Qt 4 it implies a leak under certain circumstances, which this change fixes. Task-number: QTBUG-28924 Change-Id: Id2de140de4cf676461e14b201ad250c53666b79d Reviewed-by: Olivier Goffart --- tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp') diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 9edcb8e787..f9fffaa71c 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -50,6 +50,7 @@ #include "externaltests.h" #include "forwarddeclared.h" +#include "nontracked.h" #include "wrapper.h" #include @@ -88,6 +89,7 @@ private slots: void dynamicCastDifferentPointers(); void dynamicCastVirtualBase(); void dynamicCastFailure(); + void dynamicCastFailureNoLeak(); #endif void constCorrectness(); void customDeleter(); @@ -1066,6 +1068,11 @@ void tst_QSharedPointer::dynamicCastFailure() QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); } + +void tst_QSharedPointer::dynamicCastFailureNoLeak() +{ + NonTracked::dynamicCastFailureNoLeak(); +} #endif void tst_QSharedPointer::constCorrectness() -- cgit v1.2.3