diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-10-29 15:42:21 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-11-01 09:20:59 +0100 |
commit | 891072f3f5f8f988d4da6c39ab654b605e25dda7 (patch) | |
tree | f28b1623cbaa1e017e591775be13755a3ef76847 /src/qml/qml/qqmlcomponent.cpp | |
parent | d00c76171de0c76794eb70a7284326332c0b3c66 (diff) |
QQmlComponent: Make it harder to leak deferred states
The previous pointer wrangling was ripe with foot guns. Let's just use a
vector of unique_ptr to keep track of the states.
Change-Id: I3ae225b3ab8644aa690d506d0a5de0bfb9ecce23
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlcomponent.cpp')
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 8293f17e7f..2b0e9ee31a 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1006,30 +1006,30 @@ void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv, QQmlData *ddata = QQmlData::get(object); Q_ASSERT(!ddata->deferredData.isEmpty()); - deferredState->constructionStates.reserve(ddata->deferredData.size()); + deferredState->reserve(ddata->deferredData.size()); for (QQmlData::DeferredData *deferredData : qAsConst(ddata->deferredData)) { enginePriv->inProgressCreations++; - ConstructionState *state = new ConstructionState; - state->completePending = true; + ConstructionState state; + state.completePending = true; - state->creator.reset(new QQmlObjectCreator( + state.creator.reset(new QQmlObjectCreator( deferredData->context->parent(), deferredData->compilationUnit, QQmlRefPointer<QQmlContextData>())); - if (!state->creator->populateDeferredProperties(object, deferredData)) - state->errors << state->creator->errors; + if (!state.creator->populateDeferredProperties(object, deferredData)) + state.errors << state.creator->errors; deferredData->bindings.clear(); - deferredState->constructionStates += state; + deferredState->push_back(std::move(state)); } } void QQmlComponentPrivate::completeDeferred(QQmlEnginePrivate *enginePriv, QQmlComponentPrivate::DeferredState *deferredState) { - for (ConstructionState *state : qAsConst(deferredState->constructionStates)) - complete(enginePriv, state); + for (ConstructionState &state : *deferredState) + complete(enginePriv, &state); } void QQmlComponentPrivate::complete(QQmlEnginePrivate *enginePriv, ConstructionState *state) |