[LyX/master] Avoid potential leak of memory pointed to by QTreeWidgetItem subcatItem

Stephan Witt switt at lyx.org
Fri Feb 21 06:38:25 UTC 2020


commit aec491f686546bd1db24b58a0ab7ca916f871830
Author: Stephan Witt <switt at lyx.org>
Date:   Fri Feb 21 07:57:09 2020 +0100

    Avoid potential leak of memory pointed to by QTreeWidgetItem subcatItem
---
 src/frontends/qt/GuiLyXFiles.cpp |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/frontends/qt/GuiLyXFiles.cpp b/src/frontends/qt/GuiLyXFiles.cpp
index 096a390..25b6fa4 100644
--- a/src/frontends/qt/GuiLyXFiles.cpp
+++ b/src/frontends/qt/GuiLyXFiles.cpp
@@ -445,7 +445,7 @@ void GuiLyXFiles::updateContents()
 		if (subcat.isEmpty())
 			catItem->addChild(item);
 		else {
-			QTreeWidgetItem * subcatItem = new QTreeWidgetItem();
+			QTreeWidgetItem * subcatItem = nullptr;
 			if (cats.contains(catsave)) {
 				QList<QTreeWidgetItem *> pcats = filesLW->findItems(cat, Qt::MatchExactly);
 				for (int iit = 0; iit < pcats.size(); ++iit) {
@@ -456,7 +456,9 @@ void GuiLyXFiles::updateContents()
 						}
 					}
 				}
-			} else {
+			}
+			if (!subcatItem) {
+				subcatItem = new QTreeWidgetItem();
 				subcatItem->setText(0, subcat);
 				subcatItem->setIcon(0, file_icon);
 				cats << catsave;


More information about the lyx-cvs mailing list