diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2020-06-26 09:50:09 -0700 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2020-07-31 10:40:25 -0700 |
| commit | 95afe6b244dbd9623a92399d1bed0b9f52aa1e65 (patch) | |
| tree | 8f7a79bd0b82d9d9b283c8aec1beb4d21bbea667 /src/corelib/tools/qsharedpointer.cpp | |
| parent | fe9e6b2ceb77befb77e664cda9842ff95ddf08a3 (diff) | |
QSharedPointer: do allow calling deleters on null pointers
I don't know why std::shared_ptr allows this, but why not.
[ChangeLog][Important Behavior Changes] QSharedPointer objects will now
call custom deleters even when the pointer being tracked was null. This
behavior is the same as std::shared_ptr.
Fixes: QTBUG-85285
Pick-to: 5.15
Change-Id: I24006db8360041f598c5fffd161c260df0313b55
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/corelib/tools/qsharedpointer.cpp')
| -rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index e47e0fb9604..385caa2e4bf 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -1,7 +1,8 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2020 Intel Corporation. +** Copyright (C) 2019 Klarälvdalens Datakonsult AB. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -1562,6 +1563,12 @@ void QtSharedPointer::internalSafetyCheckAdd(const void *d_ptr, const volatile v if (!kp) return; // end-game: the application is being destroyed already + if (!ptr) { + // nullptr is allowed to be tracked by more than one QSharedPointer, so we + // need something else to put in our tracking structures + ptr = d_ptr; + } + QMutexLocker lock(&kp->mutex); Q_ASSERT(!kp->dPointers.contains(d_ptr)); |
