changeset 21613:e15d3387fc59

eliminate leak in ListDialog class (bug #47372) * dialog.h, dialog.cc (ListDialog::model): New data member. (ListDialog::ListDialog): Initialize class data member instead of storing pointer in local variable. (ListDialog::~ListDialog): New function. Delete model.
author John W. Eaton <jwe@octave.org>
date Tue, 12 Apr 2016 10:10:07 -0400
parents edd0ce03f548
children 9bb39b754ab1
files libgui/src/dialog.cc libgui/src/dialog.h
diffstat 2 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/dialog.cc	Tue Apr 12 12:58:48 2016 +0100
+++ b/libgui/src/dialog.cc	Tue Apr 12 10:10:07 2016 -0400
@@ -205,12 +205,8 @@
                         int wd, int ht, const QList<int>& initial,
                         const QString& title, const QStringList& prompt,
                         const QString& ok_string, const QString& cancel_string)
-  : QDialog ()
+  : QDialog (), model (new QStringListModel (list))
 {
-  // Put the list of items into a model.  Keep this off of the stack
-  // because this conceivably could be a very large list.
-  QAbstractItemModel *model = new QStringListModel (list);
-
   QListView *view = new QListView;
   view->setModel (model);
 
@@ -306,6 +302,10 @@
            this, SLOT (item_double_clicked (const QModelIndex&)));
 }
 
+ListDialog::~ListDialog (void)
+{
+  delete model;
+}
 
 void
 ListDialog::buttonOk_clicked (void)
--- a/libgui/src/dialog.h	Tue Apr 12 12:58:48 2016 +0100
+++ b/libgui/src/dialog.h	Tue Apr 12 10:10:07 2016 -0400
@@ -199,6 +199,8 @@
                        const QString& name, const QStringList& prompt,
                        const QString& ok_string, const QString& cancel_string);
 
+  ~ListDialog (void);
+
 signals:
 
   void finish_selection (const QIntList&, int);
@@ -212,6 +214,10 @@
   void reject (void);
 
   void item_double_clicked (const QModelIndex&);
+
+private:
+
+  QAbstractItemModel *model;
 };