From db4ffd0b703b43f60b0802a21b434dd5b87f6be4 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Wed, 14 Jan 2015 13:02:18 -0200 Subject: Fix memory leak The QPainter and the QPixmap were being created but never freed. A QPixmap and a QPainter don't need to be created by new, they can be safely created on the stack. So, create them on the stack, pass them via const-reference and use them correctly. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/divetooltipitem.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'qt-ui/profile/divetooltipitem.cpp') diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index 7f7627309..dbef866c5 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -19,7 +19,7 @@ #include "display.h" #endif -void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap *pixmap) +void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap) { const IconMetrics& iconMetrics = defaultIconMetrics(); @@ -32,8 +32,8 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this); iconItem->setPos(iconMetrics.spacing, yValue); } else { - if (pixmap && !pixmap->isNull()) { - pixmapItem = new QGraphicsPixmapItem(*pixmap, this); + if (!pixmap.isNull()) { + pixmapItem = new QGraphicsPixmapItem(pixmap, this); pixmapItem->setPos(iconMetrics.spacing, yValue); } } @@ -232,8 +232,8 @@ void ToolTipItem::refresh(const QPointF &pos) { int i; struct plot_data *entry; - static QPixmap *tissues = new QPixmap(16,60); - static QPainter *painter = new QPainter(tissues); + static QPixmap tissues(16,60); + static QPainter painter(&tissues); int time = timeAxis->valueAt(pos); if (time == lastTime) return; @@ -244,21 +244,21 @@ void ToolTipItem::refresh(const QPointF &pos) entry = get_plot_details_new(&pInfo, time, &mb); if (entry) { - tissues->fill(); - painter->setPen(QColor(0, 0, 0, 0)); - painter->setBrush(QColor(LIMENADE1)); - painter->drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2); - painter->setBrush(QColor(SPRINGWOOD1)); - painter->drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2); - painter->setBrush(QColor("Red")); - painter->drawRect(0,0,16,10); - painter->setPen(QColor(0, 0, 0, 255)); - painter->drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2); - painter->drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2, + tissues.fill(); + painter.setPen(QColor(0, 0, 0, 0)); + painter.setBrush(QColor(LIMENADE1)); + painter.drawRect(0, 10 + (100 - AMB_PERCENTAGE) / 2, 16, AMB_PERCENTAGE / 2); + painter.setBrush(QColor(SPRINGWOOD1)); + painter.drawRect(0, 10, 16, (100 - AMB_PERCENTAGE) / 2); + painter.setBrush(QColor(Qt::red)); + painter.drawRect(0,0,16,10); + painter.setPen(QColor(0, 0, 0, 255)); + painter.drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2); + painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2, 16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2); - painter->setPen(QColor(0, 0, 0, 127)); + painter.setPen(QColor(0, 0, 0, 127)); for (i=0; i<16; i++) { - painter->drawLine(i, 60, i, 60 - entry->percentages[i] / 2); + painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2); } addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues); } -- cgit v1.2.3-70-g09d2