aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-03-17 17:09:10 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-19 20:00:17 +0000
commitb1f11207044d0c693101665d6457984615e3c406 (patch)
tree8e322ecebc8b5409cbeb9345f8266c9a1997bffa
parenta07c1c82d0ef1c0fff73acb2ee354a16e21b65dc (diff)
Use unique_ptr to clarify ownership of QQuickDefaultClipNode objects
The clang static analyzer warns in 3df1fff15a10a64372ed4f92ba05271f about a potential memory leak. While that particular claim is a false positive (the loop is always entered if sortedIndex is not empty), the re-use of the currentClipNode variable makes it hard to follow the object ownership, and there might still be a potential memory leak. Use std::unique_ptr to force explicit transfer of ownership, and get implicit destruction of objects not owned at the end of the scope. Change-Id: If826e1d81b92f1da60aae2262b628dcaaa2e592a Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> (cherry picked from commit 02c6e7bc3aca42a188b772aa9794b919e60017e7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index dd666416e8..38f199ecc0 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -257,7 +257,7 @@ void QQuickTextNodeEngine::processCurrentLine()
QVarLengthArray<TextDecoration> pendingOverlines;
QVarLengthArray<TextDecoration> pendingStrikeOuts;
if (!sortedIndexes.isEmpty()) {
- QQuickDefaultClipNode *currentClipNode = m_hasSelection ? new QQuickDefaultClipNode(QRectF()) : nullptr;
+ std::unique_ptr<QQuickDefaultClipNode> currentClipNode(m_hasSelection ? new QQuickDefaultClipNode(QRectF()) : nullptr);
bool currentClipNodeUsed = false;
for (int i=0; i<=sortedIndexes.size(); ++i) {
BinaryTreeNode *node = nullptr;
@@ -305,7 +305,7 @@ void QQuickTextNodeEngine::processCurrentLine()
if (currentClipNode != nullptr) {
if (!currentClipNodeUsed) {
- delete currentClipNode;
+ currentClipNode.reset();
} else {
currentClipNode->setIsRectangular(true);
currentClipNode->setRect(currentRect);
@@ -314,9 +314,9 @@ void QQuickTextNodeEngine::processCurrentLine()
}
if (node != nullptr && m_hasSelection)
- currentClipNode = new QQuickDefaultClipNode(QRectF());
+ currentClipNode.reset(new QQuickDefaultClipNode(QRectF()));
else
- currentClipNode = nullptr;
+ currentClipNode.reset(nullptr);
currentClipNodeUsed = false;
if (node != nullptr) {
@@ -336,7 +336,7 @@ void QQuickTextNodeEngine::processCurrentLine()
if (node != nullptr) {
if (node->selectionState == Selected) {
- node->clipNode = currentClipNode;
+ node->clipNode = currentClipNode.release();
currentClipNodeUsed = true;
}