diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-03-03 18:02:32 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-03-04 05:49:24 +0000 |
commit | ef34c990779cfcb068f86dd5dacfc4a7e7b58743 (patch) | |
tree | 29798f11a634891aa14979168be2568246da7602 | |
parent | 69951fec45e7b630b86989295399c980803f9b1b (diff) |
QMetaType::create: don't leak memory if copy can't be made
QMetaType::construct will return nullptr if a copy is requested but
if there is no copy constructor. In that case, the memory allocated in
QMetaType::create will be leaked.
This case is covered in the unit tests in
template<>
void testCreateHelper<QMetaType::Void>()
so we can't assert in construct that a copy constructor is present if
a copy is requested.
Fixes static analyzer warning 618b1e6877f737df57c39fd35ad91cd4.
Change-Id: Ic439b36b1f120b9d0f888efaeab2801d8acc13de
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 90b51219ddc75c4dd2d171f2dba644e67d1e4a62)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index a2e28b2d22..4e3aa48dbe 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -571,7 +571,7 @@ int QMetaType::id() const */ void *QMetaType::create(const void *copy) const { - if (d_ptr) { + if (d_ptr && (copy ? !!d_ptr->copyCtr : !!d_ptr->defaultCtr)) { void *where = #ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__ d_ptr->alignment > __STDCPP_DEFAULT_NEW_ALIGNMENT__ ? |