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:15:16 +0000
commite21819bd6374cc19a92e2b6a1ee05c0bcd5a49f6 (patch)
treeee74529a4328a94c3ddd1c478b5ce2664430800b
parent6971b1a252497b65c181d02ffac468e73997a9bb (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 c92cc7850e..52f898f72c 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -256,7 +256,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;
@@ -304,7 +304,7 @@ void QQuickTextNodeEngine::processCurrentLine()
if (currentClipNode != nullptr) {
if (!currentClipNodeUsed) {
- delete currentClipNode;
+ currentClipNode.reset();
} else {
currentClipNode->setIsRectangular(true);
currentClipNode->setRect(currentRect);
@@ -313,9 +313,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) {
@@ -335,7 +335,7 @@ void QQuickTextNodeEngine::processCurrentLine()
if (node != nullptr) {
if (node->selectionState == Selected) {
- node->clipNode = currentClipNode;
+ node->clipNode = currentClipNode.release();
currentClipNodeUsed = true;
}