diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-21 10:48:35 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-08-21 11:37:35 (GMT) |
commit | d1ced31e867f7e2bbd56daf46c7bf3cc924c8546 (patch) | |
tree | 85f027834faacdb478533c9b2aa490d802283518 /src/corelib/kernel/qvariant.cpp | |
parent | f5f89d34fa98600a95c4b1b8b62bd794ab8c8e3b (diff) | |
download | Qt-d1ced31e867f7e2bbd56daf46c7bf3cc924c8546.zip Qt-d1ced31e867f7e2bbd56daf46c7bf3cc924c8546.tar.gz Qt-d1ced31e867f7e2bbd56daf46c7bf3cc924c8546.tar.bz2 |
Fix memory leak
When the variant is invalid the shared is not destroyed.
We even can avoid the creation of the PrivateShared if we know the
variant is invalid
Reviewed-by: Thierry
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index a91fb75..9adfa57 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -174,10 +174,13 @@ static void construct(QVariant::Private *x, const void *copy) case QVariant::UserType: break; default: - x->is_shared = true; - x->data.shared = new QVariant::PrivateShared(QMetaType::construct(x->type, copy)); - if (!x->data.shared->ptr) + void *ptr = QMetaType::construct(x->type, copy); + if (!ptr) { x->type = QVariant::Invalid; + } else { + x->is_shared = true; + x->data.shared = new QVariant::PrivateShared(ptr); + } break; } x->is_null = !copy; |