Skip to content

Commit 0d15804

Browse files
committed
fix: clang-analyzer-cplusplus.NewDeleteLeaks
- potential leak of memory
1 parent d4a8f4b commit 0d15804

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/api/UBWidgetUniboardAPI.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ bool UBWidgetUniboardAPI::ProcessDropEvent(QGraphicsSceneDragDropEvent *event)
565565

566566
if (!UBFileSystemUtils::copyFile(fileName, destFileName)) {
567567
qDebug() << "can't copy from" << fileName << "to" << destFileName;
568+
delete dropMimeData;
568569
return false;
569570
}
570571
downloaded = true;

src/document/UBDocumentController.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,11 @@ QModelIndex UBDocumentTreeModel::goTo(const QString &dir)
12221222
if (!searchingNode) {
12231223
UBDocumentTreeNode *newChild = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, curLevelName);
12241224
parentIndex = addNode(newChild, parentIndex);
1225+
1226+
if (!parentIndex.isValid())
1227+
{
1228+
delete newChild;
1229+
}
12251230
}
12261231
}
12271232

@@ -1266,7 +1271,10 @@ void UBDocumentTreeModel::addDocument(std::shared_ptr<UBDocumentProxy> pProxyDat
12661271
lParent = goTo(docGroupName);
12671272
}
12681273

1269-
addNode(freeNode, lParent);
1274+
if (!addNode(freeNode, lParent).isValid())
1275+
{
1276+
delete freeNode;
1277+
}
12701278
}
12711279

12721280
void UBDocumentTreeModel::addNewDocument(std::shared_ptr<UBDocumentProxy> pProxyData, const QModelIndex &pParent)
@@ -1281,7 +1289,14 @@ QModelIndex UBDocumentTreeModel::addCatalog(const QString &pName, const QModelIn
12811289
}
12821290

12831291
UBDocumentTreeNode *catalogNode = new UBDocumentTreeNode(UBDocumentTreeNode::Catalog, pName);
1284-
return addNode(catalogNode, pParent);
1292+
QModelIndex index = addNode(catalogNode, pParent);
1293+
1294+
if (!index.isValid())
1295+
{
1296+
delete catalogNode;
1297+
}
1298+
1299+
return index;
12851300
}
12861301

12871302
void UBDocumentTreeModel::setNewName(const QModelIndex &index, const QString &newName)
@@ -2230,6 +2245,8 @@ void UBDocumentController::setupViews()
22302245
adaptor->setAssociatedAction(currentExportAction);
22312246
}
22322247

2248+
bool exportMenuAttached = false;
2249+
22332250
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
22342251
foreach (QObject* menuWidget, mMainWindow->actionExport->associatedObjects())
22352252
#else
@@ -2244,9 +2261,15 @@ void UBDocumentController::setupViews()
22442261
tb->setPopupMode(QToolButton::InstantPopup);
22452262

22462263
tb->setMenu(exportMenu);
2264+
exportMenuAttached = true;
22472265
}
22482266
}
22492267

2268+
if (!exportMenuAttached)
2269+
{
2270+
delete exportMenu;
2271+
}
2272+
22502273
#ifdef Q_OS_OSX
22512274
mMainWindow->actionDelete->setShortcut(QKeySequence(Qt::Key_Backspace));
22522275
#else

0 commit comments

Comments
 (0)