summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-01-03 15:17:21 -0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-04 17:30:19 +0100
commita094bf5a893c3cccffff10c1420bfbe3a3c02a7c (patch)
treec4c6d05db0103b124da7650f1df8b10fa5ab0a4f /tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
parentbf5e7fb2652669599a508e049b46ebd5cd3206e5 (diff)
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 <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp')
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp7
1 files changed, 7 insertions, 0 deletions
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 <stdlib.h>
@@ -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()