Skip to content

Commit

Permalink
ProfileTreeView: fix a memory leak
Browse files Browse the repository at this point in the history
In the constructor, we allocate a delegate for the name column and assign
it by calling QAbstractItemView::setItemDelegateForColumn(). This does
not pass ownership of the delegate to QAbstractItemView, it's still
up to us to free the delegate.

ASAN warns about this

Indirect leak of 48 byte(s) in 1 object(s) allocated from:
...
    #1 ... in ProfileTreeView::ProfileTreeView(QWidget*) ui/qt/widgets/profile_tree_view.cpp:46:17
    #2 ... in Ui_ProfileDialog::setupUi(QDialog*) ui/qt/qtui_autogen/include/ui_profile_dialog.h:67:31
    #3 ... in ProfileDialog::ProfileDialog(QWidget*) ui/qt/profile_dialog.cpp:59:13
    #4 ... in MainWindow::on_actionEditConfigurationProfiles_triggered() ui/qt/main_window_slots.cpp:2239:36

Add a destructor for ProfileTreeView and free the delegate there.

Change-Id: I2a76abb7ec174c91ad15bfac91f2b47bea29f511
Reviewed-on: https://code.wireshark.org/review/36934
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
  • Loading branch information
martin-kaiser authored and AndersBroman committed Apr 26, 2020
1 parent 3485ad6 commit d8137cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ui/qt/widgets/profile_tree_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ ProfileTreeView::ProfileTreeView(QWidget *parent) :
connect(delegate_, SIGNAL(commitData(QWidget *)), this, SIGNAL(itemUpdated()));
}

ProfileTreeView::~ProfileTreeView()
{
delete delegate_;
}

void ProfileTreeView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
QTreeView::selectionChanged(selected, deselected);
Expand Down
1 change: 1 addition & 0 deletions ui/qt/widgets/profile_tree_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ProfileTreeView : public QTreeView
Q_OBJECT
public:
ProfileTreeView(QWidget *parent = nullptr);
~ProfileTreeView();

void selectRow(int row);
bool activeEdit();
Expand Down

0 comments on commit d8137cc

Please sign in to comment.