From 3bb0cf4ad7166860fb7b81b1bbe1d84d86d4203c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Oct 2010 15:27:11 +0200 Subject: Fix access to uninitialised memory in case of new throwing Testing will come later with a full test for exception issues Task-number: QTBUG-14637 Reviewed-by: Olivier Goffart --- src/corelib/tools/qsharedpointer_impl.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 4cce339..2519a22 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -378,6 +378,13 @@ namespace QtSharedPointer { inline ExternalRefCount() : d(0) { } inline ExternalRefCount(Qt::Initialization i) : Basic(i) { } + + inline ExternalRefCount(T *ptr) : Basic(Qt::Uninitialized) // throws + { internalConstruct(ptr); } + template + inline ExternalRefCount(T *ptr, Deleter d) : Basic(Qt::Uninitialized) // throws + { internalConstruct(ptr, d); } + inline ExternalRefCount(const ExternalRefCount &other) : Basic(other), d(other.d) { if (d) ref(); } template @@ -448,11 +455,12 @@ public: inline QSharedPointer() { } // inline ~QSharedPointer() { } - inline explicit QSharedPointer(T *ptr) : BaseClass(Qt::Uninitialized) - { BaseClass::internalConstruct(ptr); } + inline explicit QSharedPointer(T *ptr) : BaseClass(ptr) // throws + { } template - inline QSharedPointer(T *ptr, Deleter d) { BaseClass::internalConstruct(ptr, d); } + inline QSharedPointer(T *ptr, Deleter d) : BaseClass(ptr, d) // throws + { } inline QSharedPointer(const QSharedPointer &other) : BaseClass(other) { } inline QSharedPointer &operator=(const QSharedPointer &other) -- cgit v0.12