forked from osmocom/wireshark
Qt: fix memleak of PointList in interface statistics
The list of points (for interface traffic statistics) is part of the interface tree model/view. Remove the pointer indirection to simplify cleanup and avoid leaking a PointList. Note that the SparkLineDelegate is used in two different places (CaptureInterfacesDialog and InterfaceTreeModel). Change-Id: I5fef7dadd44fdf58c07844fee269f509c712a36f Reviewed-on: https://code.wireshark.org/review/19606 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
parent
4b3b3f5877
commit
f8dc2346df
|
@ -648,7 +648,7 @@ void CaptureInterfacesDialog::updateInterfaces()
|
|||
InterfaceTreeWidgetItem *ti = new InterfaceTreeWidgetItem(ui->interfaceTree);
|
||||
ti->setFlags(ti->flags() | Qt::ItemIsEditable);
|
||||
ti->setData(col_interface_, Qt::UserRole, QString(device->name));
|
||||
ti->setData(col_traffic_, Qt::UserRole, qVariantFromValue(&ti->points));
|
||||
ti->setData(col_traffic_, Qt::UserRole, qVariantFromValue(ti->points));
|
||||
|
||||
ti->setText(col_interface_, device->display_name);
|
||||
if (device->no_addresses > 0) {
|
||||
|
@ -766,8 +766,8 @@ void CaptureInterfacesDialog::updateStatistics(void)
|
|||
if (device_name.compare(device->display_name) || device->hidden || device->type == IF_PIPE) {
|
||||
continue;
|
||||
}
|
||||
QList<int> *points = ti->data(col_traffic_, Qt::UserRole).value<QList<int> *>();
|
||||
points->append(device->packet_diff);
|
||||
QList<int> points = ti->data(col_traffic_, Qt::UserRole).value<QList<int> >();
|
||||
points.append(device->packet_diff);
|
||||
ti->setData(col_traffic_, Qt::UserRole, qVariantFromValue(points));
|
||||
}
|
||||
}
|
||||
|
@ -1101,14 +1101,14 @@ interface_t *CaptureInterfacesDialog::getDeviceByName(const QString device_name)
|
|||
//
|
||||
bool InterfaceTreeWidgetItem::operator< (const QTreeWidgetItem &other) const {
|
||||
if (treeWidget()->sortColumn() == col_traffic_) {
|
||||
QList<int> *points = data(col_traffic_, Qt::UserRole).value<QList<int> *>();
|
||||
QList<int> *other_points = other.data(col_traffic_, Qt::UserRole).value<QList<int> *>();
|
||||
QList<int> points = data(col_traffic_, Qt::UserRole).value<QList<int> >();
|
||||
QList<int> other_points = other.data(col_traffic_, Qt::UserRole).value<QList<int> >();
|
||||
double avg = 0, other_avg = 0;
|
||||
foreach (int point, *points) {
|
||||
avg += (double) point / points->length();
|
||||
foreach (int point, points) {
|
||||
avg += (double) point / points.length();
|
||||
}
|
||||
foreach (int point, *other_points) {
|
||||
other_avg += (double) point / other_points->length();
|
||||
foreach (int point, other_points) {
|
||||
other_avg += (double) point / other_points.length();
|
||||
}
|
||||
return avg < other_avg;
|
||||
}
|
||||
|
|
|
@ -338,12 +338,6 @@ void InterfaceTreeModel::interfaceListChanged()
|
|||
{
|
||||
emit beginResetModel();
|
||||
|
||||
QMap<QString, PointList *>::const_iterator it = points.constBegin();
|
||||
while(it != points.constEnd())
|
||||
{
|
||||
it.value()->clear();
|
||||
++it;
|
||||
}
|
||||
points.clear();
|
||||
|
||||
emit endResetModel();
|
||||
|
@ -435,9 +429,6 @@ void InterfaceTreeModel::updateStatistic(unsigned int idx)
|
|||
|
||||
struct pcap_stat stats;
|
||||
|
||||
if ( !points.contains(device.name) )
|
||||
points.insert(device.name, new PointList());
|
||||
|
||||
diff = 0;
|
||||
if ( capture_stats(stat_cache_, device.name, &stats) )
|
||||
{
|
||||
|
@ -452,7 +443,7 @@ void InterfaceTreeModel::updateStatistic(unsigned int idx)
|
|||
g_array_insert_val(global_capture_opts.all_ifaces, idx, device);
|
||||
}
|
||||
|
||||
points[device.name]->append(diff);
|
||||
points[device.name].append(diff);
|
||||
emit dataChanged(index(idx, IFTREE_COL_STATS), index(idx, IFTREE_COL_STATS));
|
||||
#else
|
||||
Q_UNUSED(idx);
|
||||
|
@ -467,7 +458,7 @@ void InterfaceTreeModel::getPoints(int idx, PointList *pts)
|
|||
|
||||
interface_t device = g_array_index(global_capture_opts.all_ifaces, interface_t, idx);
|
||||
if ( points.contains(device.name) )
|
||||
pts->append(*points[device.name]);
|
||||
pts->append(points[device.name]);
|
||||
#else
|
||||
Q_UNUSED(idx);
|
||||
Q_UNUSED(pts);
|
||||
|
|
|
@ -102,7 +102,7 @@ protected slots:
|
|||
|
||||
private:
|
||||
QVariant toolTipForInterface(int idx) const;
|
||||
QMap<QString, PointList *> points;
|
||||
QMap<QString, PointList> points;
|
||||
|
||||
#ifdef HAVE_LIBPCAP
|
||||
if_stat_cache_t *stat_cache_;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
void SparkLineDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QList<int> *points = qvariant_cast<QList<int> *>(index.data(Qt::UserRole));
|
||||
QList<int> points = qvariant_cast<QList<int> >(index.data(Qt::UserRole));
|
||||
int max = 1;
|
||||
int em_w = option.fontMetrics.height();
|
||||
int content_w = option.rect.width() - (em_w / 4);
|
||||
|
@ -42,19 +42,19 @@ void SparkLineDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opt
|
|||
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (!points || points->isEmpty() || steps < 1.0 || content_h <= 0) {
|
||||
if (points.isEmpty() || steps < 1.0 || content_h <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while((qreal) points->length() > steps) {
|
||||
points->removeFirst();
|
||||
while((qreal) points.length() > steps) {
|
||||
points.removeFirst();
|
||||
}
|
||||
|
||||
foreach (val, *points) {
|
||||
foreach (val, points) {
|
||||
if (val > max) max = val;
|
||||
}
|
||||
|
||||
foreach (val, *points) {
|
||||
foreach (val, points) {
|
||||
fpoints.append(QPointF(idx, (qreal) content_h - (val * content_h / max)));
|
||||
idx = idx + step_w;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue