From dc4764229a3eef5c0bdbd665f2e24e59398e8c51 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 20 Sep 2011 15:23:03 +0200 Subject: [blitter] Use QScopedPointer for the engine and blittable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the QScopedPointer to prevent memory leaks, right now the code appears to be sound but make it more clear that calling ::setBlittable will destroy the old one. Change-Id: Idc71add7cfd429ff5b9d0ea9908d9fff1e7ce74d Merge-request: 59 Reviewed-on: http://codereview.qt-project.org/5243 Reviewed-by: Jørgen Lind --- src/gui/image/qpixmap_blitter.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/gui/image/qpixmap_blitter.cpp') diff --git a/src/gui/image/qpixmap_blitter.cpp b/src/gui/image/qpixmap_blitter.cpp index dc0f03abdc..25801dbd4c 100644 --- a/src/gui/image/qpixmap_blitter.cpp +++ b/src/gui/image/qpixmap_blitter.cpp @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE static int global_ser_no = 0; QBlittablePlatformPixmap::QBlittablePlatformPixmap() - : QPlatformPixmap(QPlatformPixmap::PixmapType,BlitterClass), m_engine(0), m_blittable(0) + : QPlatformPixmap(QPlatformPixmap::PixmapType,BlitterClass) #ifdef QT_BLITTER_RASTEROVERLAY ,m_rasterOverlay(0), m_unmergedCopy(0) #endif //QT_BLITTER_RASTEROVERLAY @@ -67,8 +67,6 @@ QBlittablePlatformPixmap::QBlittablePlatformPixmap() QBlittablePlatformPixmap::~QBlittablePlatformPixmap() { - delete m_blittable; - delete m_engine; #ifdef QT_BLITTER_RASTEROVERLAY delete m_rasterOverlay; delete m_unmergedCopy; @@ -79,25 +77,22 @@ QBlittable *QBlittablePlatformPixmap::blittable() const { if (!m_blittable) { QBlittablePlatformPixmap *that = const_cast(this); - that->m_blittable = this->createBlittable(QSize(w,h)); + that->m_blittable.reset(this->createBlittable(QSize(w, h))); } - return m_blittable; + return m_blittable.data(); } void QBlittablePlatformPixmap::setBlittable(QBlittable *blittable) { resize(blittable->size().width(),blittable->size().height()); - m_blittable = blittable; + m_blittable.reset(blittable); } void QBlittablePlatformPixmap::resize(int width, int height) { - - delete m_blittable; - m_blittable = 0; - delete m_engine; - m_engine = 0; + m_blittable.reset(0); + m_engine.reset(0); #ifdef Q_WS_QPA d = QGuiApplication::primaryScreen()->depth(); #endif @@ -208,9 +203,9 @@ QPaintEngine *QBlittablePlatformPixmap::paintEngine() const { if (!m_engine) { QBlittablePlatformPixmap *that = const_cast(this); - that->m_engine = new QBlitterPaintEngine(that); + that->m_engine.reset(new QBlitterPaintEngine(that)); } - return m_engine; + return m_engine.data(); } #ifdef QT_BLITTER_RASTEROVERLAY -- cgit v1.2.3