From 24c930d727f68976851f6bade8b49afcea616ea5 Mon Sep 17 00:00:00 2001 From: Simon De Backer Date: Fri, 30 Oct 2020 21:07:12 +0100 Subject: [PATCH] Mod raw Pointer to QScopedPointer Clang-Tidy and Clazy said "drag" leaks memory --- .../ElementsCollection/elementstreeview.cpp | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/sources/ElementsCollection/elementstreeview.cpp b/sources/ElementsCollection/elementstreeview.cpp index 9f00f8fe2..70a53fbb9 100644 --- a/sources/ElementsCollection/elementstreeview.cpp +++ b/sources/ElementsCollection/elementstreeview.cpp @@ -69,10 +69,9 @@ void ElementsTreeView::startDrag(Qt::DropActions supportedActions) */ void ElementsTreeView::startElementDrag(const ElementsLocation &location) { - if (!location.exist()) - return; + if (! location.exist()) return; - QDrag *drag = new QDrag(this); + QScopedPointer drag(new QDrag(this)); QString location_str = location.toString(); QMimeData *mime_data = new QMimeData(); @@ -91,14 +90,12 @@ void ElementsTreeView::startElementDrag(const ElementsLocation &location) //Build the element for set the pixmap of the QDrag int elmt_creation_state; - Element *temp_elmt = ElementFactory::Instance()->createElement( - location, nullptr, - &elmt_creation_state); - if (elmt_creation_state) - { - delete temp_elmt; - return; - } + QScopedPointer temp_elmt( + ElementFactory::Instance()->createElement( + location, + nullptr, + &elmt_creation_state)); + if (elmt_creation_state) { return; } QPixmap elmt_pixmap(temp_elmt->pixmap()); QPoint elmt_hotspot(temp_elmt->hotspot()); @@ -123,9 +120,6 @@ void ElementsTreeView::startElementDrag(const ElementsLocation &location) drag->setPixmap(elmt_pixmap); drag->setHotSpot(elmt_hotspot); - - - delete temp_elmt; } drag->setMimeData(mime_data);