diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-01-03 17:17:21 (GMT) |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-05 13:46:00 (GMT) |
commit | 40e44d197777cf9a57189d0266540053d36f5ad7 (patch) | |
tree | a75d6ccaa59891010b4a92aa027a15a18163501e /src/corelib/tools/qsharedpointer_impl.h | |
parent | e90c65e609380c218ea25eada6fbdcad554f3ae7 (diff) | |
download | Qt-40e44d197777cf9a57189d0266540053d36f5ad7.zip Qt-40e44d197777cf9a57189d0266540053d36f5ad7.tar.gz Qt-40e44d197777cf9a57189d0266540053d36f5ad7.tar.bz2 |
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
(cherry-picked from qt5 commit a094bf5a893c3cccffff10c1420bfbe3a3c02a7c)
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qsharedpointer_impl.h')
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index dc57d60..013ab83 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -832,6 +832,8 @@ template <class X, class T> Q_INLINE_TEMPLATE QSharedPointer<X> qSharedPointerDynamicCast(const QSharedPointer<T> &src) { register X *ptr = dynamic_cast<X *>(src.data()); // if you get an error in this line, the cast is invalid + if (!ptr) + return QSharedPointer<X>(); return QtSharedPointer::copyAndSetPointer(ptr, src); } template <class X, class T> |