aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2022-09-13 23:21:49 -0400
committerA Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2022-09-14 12:43:55 +0000
commitcbb22130217b86a5ca2b422103210f4e0533dc08 (patch)
tree24b4f3308558f58789067209e412ef3076fde579
parentc0ba61fbf2fbcc2e6ee596409441118204f15412 (diff)
Qt: Fix memory leak in Decode As
The correct place to delete the dissector_info_t pointers added to the editor is when destroyEditor is called. Override the virtual function and delete the pointers for the colProtocol index before calling the inherited function. Fix #17127
-rw-r--r--ui/qt/models/decode_as_delegate.cpp11
-rw-r--r--ui/qt/models/decode_as_delegate.h7
2 files changed, 15 insertions, 3 deletions
diff --git a/ui/qt/models/decode_as_delegate.cpp b/ui/qt/models/decode_as_delegate.cpp
index d2898a46e7..c1161ed13a 100644
--- a/ui/qt/models/decode_as_delegate.cpp
+++ b/ui/qt/models/decode_as_delegate.cpp
@@ -289,6 +289,17 @@ QWidget* DecodeAsDelegate::createEditor(QWidget *parentWidget, const QStyleOptio
return editor;
}
+void DecodeAsDelegate::destroyEditor(QWidget *editor, const QModelIndex &index) const
+{
+ if (index.column() == DecodeAsModel::colProtocol) {
+ QComboBox *cb_editor = (QComboBox*)editor;
+ for (int i=0; i < cb_editor->count(); ++i) {
+ delete VariantPointer<dissector_info_t>::asPtr(cb_editor->itemData(i));
+ }
+ }
+ QStyledItemDelegate::destroyEditor(editor, index);
+}
+
void DecodeAsDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
DecodeAsItem* item = indexToField(index);
diff --git a/ui/qt/models/decode_as_delegate.h b/ui/qt/models/decode_as_delegate.h
index 058ca9e7f7..d045776462 100644
--- a/ui/qt/models/decode_as_delegate.h
+++ b/ui/qt/models/decode_as_delegate.h
@@ -34,10 +34,11 @@ public:
DecodeAsDelegate(QObject *parent = 0, capture_file *cf = NULL);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
- const QModelIndex &index) const;
- void setEditorData(QWidget *editor, const QModelIndex &index) const;
+ const QModelIndex &index) const override;
+ void destroyEditor(QWidget *editor, const QModelIndex &index) const override;
+ void setEditorData(QWidget *editor, const QModelIndex &index) const override;
void setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const;
+ const QModelIndex &index) const override;
#if 0
void updateEditorGeometry(QWidget *editor,