From c4fc1bf1c905ab38f9fb8831aa1c878d1d7b4a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sat, 9 Jul 2022 22:32:48 +0200 Subject: [PATCH] fixed memory leak in `cppcheck-gui` (#4248) * settingsdialog.cpp: fixed memory leak Direct leak of 200 byte(s) in 1 object(s) allocated from: #0 0xa15a2d in operator new(unsigned long) (/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-asan-ubsan/bin/cppcheck-gui+0xa15a2d) #1 0xe639af in SettingsDialog::SettingsDialog(ApplicationList*, TranslationHandler*, QWidget*) /mnt/s/GitHub/cppcheck-fw/gui/settingsdialog.cpp:75:21 #2 0xc67807 in MainWindow::programSettings() /mnt/s/GitHub/cppcheck-fw/gui/mainwindow.cpp:1064:20 #3 0xd1deb8 in QtPrivate::FunctorCall, QtPrivate::List<>, void, void (MainWindow::*)()>::call(void (MainWindow::*)(), MainWindow*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:152:13 #4 0xd1db5c in void QtPrivate::FunctionPointer::call, void>(void (MainWindow::*)(), MainWindow*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:185:13 #5 0xd1d675 in QtPrivate::QSlotObject, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:418:17 #6 0x7f9687f26132 (/usr/lib/x86_64-linux-gnu/libQt5Core.so.5+0x2e6132) #7 0x7f96889ccdc1 in QAction::triggered(bool) (/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x15cdc1) * resultstree.cpp: adjusted TODO about memory leaks --- gui/resultstree.cpp | 14 +++++++++++++- gui/settingsdialog.cpp | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index caa80bb7d..6cf1e12be 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -316,7 +316,19 @@ QStandardItem *ResultsTree::addBacktraceFiles(QStandardItem *parent, list[0]->setIcon(QIcon(icon)); } - //TODO Does this leak memory? Should items from list be deleted? + /* TODO: the list items leak memory + Indirect leak of 80624 byte(s) in 5039 object(s) allocated from: + #0 0xa15a2d in operator new(unsigned long) (/mnt/s/GitHub/cppcheck-fw/cmake-build-debug-wsl-kali-clang-asan-ubsan/bin/cppcheck-gui+0xa15a2d) + #1 0xdda276 in ResultsTree::createNormalItem(QString const&) /mnt/s/GitHub/cppcheck-fw/gui/resultstree.cpp:122:27 + #2 0xde4290 in ResultsTree::addBacktraceFiles(QStandardItem*, ErrorLine const&, bool, QString const&, bool) /mnt/s/GitHub/cppcheck-fw/gui/resultstree.cpp:289:13 + #3 0xddd754 in ResultsTree::addErrorItem(ErrorItem const&) /mnt/s/GitHub/cppcheck-fw/gui/resultstree.cpp:199:30 + #4 0xe37046 in ResultsView::error(ErrorItem const&) /mnt/s/GitHub/cppcheck-fw/gui/resultsview.cpp:129:21 + #5 0xd2448d in QtPrivate::FunctorCall, QtPrivate::List, void, void (ResultsView::*)(ErrorItem const&)>::call(void (ResultsView::*)(ErrorItem const&), ResultsView*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:152:13 + #6 0xd2402c in void QtPrivate::FunctionPointer::call, void>(void (ResultsView::*)(ErrorItem const&), ResultsView*, void**) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:185:13 + #7 0xd23b45 in QtPrivate::QSlotObject, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:418:17 + #8 0x7fd2536cc0dd in QObject::event(QEvent*) (/usr/lib/x86_64-linux-gnu/libQt5Core.so.5+0x2dc0dd) + #9 0x7fd2541836be in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5+0x1636be) + */ return list[0]; } diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 6e4d5fa2e..10d6aff27 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -115,6 +115,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list, SettingsDialog::~SettingsDialog() { saveSettings(); + delete mCurrentStyle; delete mUI; }