diff options
author | Peter Wu <peter@lekensteyn.nl> | 2017-06-26 23:40:22 +0200 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2017-06-27 21:16:10 +0000 |
commit | 6bc0ba845100acb3c721e4f945bafeb1bed6c942 (patch) | |
tree | b494ef606a66643fce9be1d46c075ec57449326b /ui/qt/interface_tree_cache_model.cpp | |
parent | 381fd410cbea10207d15ee9bd05eaa18f91c60ac (diff) | |
download | wireshark-6bc0ba845100acb3c721e4f945bafeb1bed6c942.tar.gz |
Qt: fix alloc-dealloc-mismatch while adding named pipe
ManageInterfacesDialog::on_addPipe_clicked uses g_new0 to create an
"interface_t" instance, but InterfaceTreeCacheModel uses qDeleteAll
which results in ASAN reporting "alloc-dealloc-mismatch (malloc vs
operator delete)".
To fix this, remove the dynamic allocation and make
InterfaceTreeCacheModel store the instance internally.
Change-Id: I9426dfc88d0a54a889bbbc9cf336c0a6af76920e
Reviewed-on: https://code.wireshark.org/review/22410
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt/interface_tree_cache_model.cpp')
-rw-r--r-- | ui/qt/interface_tree_cache_model.cpp | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/ui/qt/interface_tree_cache_model.cpp b/ui/qt/interface_tree_cache_model.cpp index 5447f80332..3b9f6d56b6 100644 --- a/ui/qt/interface_tree_cache_model.cpp +++ b/ui/qt/interface_tree_cache_model.cpp @@ -62,11 +62,7 @@ InterfaceTreeCacheModel::~InterfaceTreeCacheModel() { #ifdef HAVE_LIBPCAP /* This list should only exist, if the dialog is closed, without calling save first */ - if ( newDevices.size() > 0 ) - { - qDeleteAll(newDevices); - newDevices.clear(); - } + newDevices.clear(); #endif delete storage; @@ -95,7 +91,7 @@ void InterfaceTreeCacheModel::reset(int row) void InterfaceTreeCacheModel::saveNewDevices() { - QList<interface_t *>::const_iterator it = newDevices.constBegin(); + QList<interface_t>::const_iterator it = newDevices.constBegin(); /* idx is used for iterating only over the indices of the new devices. As all new * devices are stored with an index higher then sourceModel->rowCount(), we start * only with those storage indices. @@ -103,7 +99,7 @@ void InterfaceTreeCacheModel::saveNewDevices() * have storage, which will lead to that device not being stored in global_capture_opts */ for (int idx = sourceModel->rowCount(); it != newDevices.constEnd(); ++it, idx++) { - interface_t * device = (interface_t *)(*it); + interface_t *device = const_cast<interface_t *>(&(*it)); bool useDevice = false; QMap<InterfaceTreeColumns, QVariant> * dataField = storage->value(idx, 0); @@ -143,7 +139,6 @@ void InterfaceTreeCacheModel::saveNewDevices() delete dataField; } - qDeleteAll(newDevices); newDevices.clear(); } @@ -321,9 +316,9 @@ bool InterfaceTreeCacheModel::changeIsAllowed(InterfaceTreeColumns col) const } #ifdef HAVE_LIBPCAP -interface_t * InterfaceTreeCacheModel::lookup(const QModelIndex &index) const +const interface_t * InterfaceTreeCacheModel::lookup(const QModelIndex &index) const { - interface_t * result = 0; + const interface_t * result = 0; if ( ! index.isValid() ) return result; @@ -336,7 +331,7 @@ interface_t * InterfaceTreeCacheModel::lookup(const QModelIndex &index) const { idx = idx - global_capture_opts.all_ifaces->len; if ( idx < newDevices.size() ) - result = newDevices[idx]; + result = &newDevices[idx]; } else { @@ -355,7 +350,7 @@ bool InterfaceTreeCacheModel::isAllowedToBeEdited(const QModelIndex &index) cons Q_UNUSED(index) #ifdef HAVE_LIBPCAP - interface_t * device = lookup(index); + const interface_t * device = lookup(index); if ( device == 0 ) return false; @@ -383,7 +378,7 @@ bool InterfaceTreeCacheModel::isAvailableField(const QModelIndex &index) const Q_UNUSED(index) #ifdef HAVE_LIBPCAP - interface_t * device = lookup(index); + const interface_t * device = lookup(index); if ( device == 0 ) return false; @@ -502,7 +497,7 @@ QVariant InterfaceTreeCacheModel::data(const QModelIndex &index, int role) const * are supported at the moment, so the information to be displayed is pretty limited. * After saving, the devices are stored in global_capture_opts and no longer * classify as new devices. */ - interface_t * device = lookup(index); + const interface_t * device = lookup(index); if ( device != 0 ) { @@ -557,10 +552,10 @@ QModelIndex InterfaceTreeCacheModel::index(int row, int column, const QModelInde return sourceModel->index(row, column, parent); } -void InterfaceTreeCacheModel::addDevice(interface_t * newDevice) +void InterfaceTreeCacheModel::addDevice(const interface_t * newDevice) { emit beginInsertRows(QModelIndex(), rowCount(), rowCount()); - newDevices << newDevice; + newDevices << *newDevice; emit endInsertRows(); } |