diff options
author | Robert Griebl <rgriebl@trolltech.com> | 2009-06-10 11:46:23 (GMT) |
---|---|---|
committer | Robert Griebl <rgriebl@trolltech.com> | 2009-06-10 11:46:23 (GMT) |
commit | 7604f8087f88171ef933d8ae08f501467e647338 (patch) | |
tree | 51d071f462ed48d0b25884d9f62b8ba11c5dff13 /src/gui/painting | |
parent | 8c265860b41214daade7c8a28237c1e07ea71a3c (diff) | |
download | Qt-7604f8087f88171ef933d8ae08f501467e647338.zip Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.gz Qt-7604f8087f88171ef933d8ae08f501467e647338.tar.bz2 |
Make Qt exception safer.
Squashed commit of the branch haralds-haralds-qt-s60-topics/topic/exceptions,
which also contains the full history.
Rev-By: Harald Fernengel
Rev-By: Ralf Engels
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qbrush.cpp | 113 | ||||
-rw-r--r-- | src/gui/painting/qbrush.h | 6 | ||||
-rw-r--r-- | src/gui/painting/qdrawhelper.cpp | 4 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine.cpp | 1 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine.h | 3 | ||||
-rw-r--r-- | src/gui/painting/qpaintengine_raster.cpp | 168 | ||||
-rw-r--r-- | src/gui/painting/qpainter.cpp | 61 | ||||
-rw-r--r-- | src/gui/painting/qpainter.h | 5 | ||||
-rw-r--r-- | src/gui/painting/qpainterpath.cpp | 21 | ||||
-rw-r--r-- | src/gui/painting/qpainterpath.h | 9 | ||||
-rw-r--r-- | src/gui/painting/qprinter.cpp | 1 | ||||
-rw-r--r-- | src/gui/painting/qprinter.h | 5 | ||||
-rw-r--r-- | src/gui/painting/qprinterinfo.h | 3 | ||||
-rw-r--r-- | src/gui/painting/qprinterinfo_mac.cpp | 32 | ||||
-rw-r--r-- | src/gui/painting/qprinterinfo_unix.cpp | 33 | ||||
-rw-r--r-- | src/gui/painting/qprinterinfo_win.cpp | 30 | ||||
-rw-r--r-- | src/gui/painting/qrasterizer.cpp | 7 | ||||
-rw-r--r-- | src/gui/painting/qregion.cpp | 160 | ||||
-rw-r--r-- | src/gui/painting/qwindowsurface_raster.cpp | 2 | ||||
-rw-r--r-- | src/gui/painting/qwindowsurface_raster_p.h | 2 |
20 files changed, 392 insertions, 274 deletions
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 854d0aa..c22791a 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -221,7 +221,7 @@ bool qHasPixmapTexture(const QBrush& brush) { if (brush.style() != Qt::TexturePattern) return false; - QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d); + QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d.data()); return tx_data->m_has_pixmap_texture; } @@ -230,6 +230,37 @@ struct QGradientBrushData : public QBrushData QGradient gradient; }; +struct QBrushDataPointerHandler +{ + static inline void deleteData(QBrushData *d) + { + switch (d->style) { + case Qt::TexturePattern: + delete static_cast<QTexturedBrushData*>(d); + break; + case Qt::LinearGradientPattern: + case Qt::RadialGradientPattern: + case Qt::ConicalGradientPattern: + delete static_cast<QGradientBrushData*>(d); + break; + default: + delete d; + } + } + + static inline void cleanup(QBrushData *d) + { + if (d && !d->ref.deref()) { + deleteData(d); + } + } + + static inline void reset(QBrushData *&d, QBrushData *other) + { + cleanup(d); + d = other; + } +}; /*! \class QBrush @@ -364,20 +395,20 @@ void QBrush::init(const QColor &color, Qt::BrushStyle style) { switch(style) { case Qt::NoBrush: - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); if (d->color != color) setColor(color); return; case Qt::TexturePattern: - d = new QTexturedBrushData; + d.data_ptr() = new QTexturedBrushData; break; case Qt::LinearGradientPattern: case Qt::RadialGradientPattern: case Qt::ConicalGradientPattern: - d = new QGradientBrushData; + d.data_ptr() = new QGradientBrushData; break; default: - d = new QBrushData; + d.data_ptr() = new QBrushData; break; } d->ref = 1; @@ -391,8 +422,8 @@ void QBrush::init(const QColor &color, Qt::BrushStyle style) */ QBrush::QBrush() + : d(nullBrushInstance()) { - d = nullBrushInstance(); Q_ASSERT(d); d->ref.ref(); } @@ -435,7 +466,7 @@ QBrush::QBrush(Qt::BrushStyle style) if (qbrush_check_type(style)) init(Qt::black, style); else { - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); } } @@ -451,7 +482,7 @@ QBrush::QBrush(const QColor &color, Qt::BrushStyle style) if (qbrush_check_type(style)) init(color, style); else { - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); } } @@ -468,7 +499,7 @@ QBrush::QBrush(Qt::GlobalColor color, Qt::BrushStyle style) if (qbrush_check_type(style)) init(color, style); else { - d = nullBrushInstance(); + d.data_ptr() = nullBrushInstance(); d->ref.ref(); } } @@ -510,8 +541,8 @@ QBrush::QBrush(Qt::GlobalColor color, const QPixmap &pixmap) */ QBrush::QBrush(const QBrush &other) + : d(other.d.data()) { - d = other.d; d->ref.ref(); } @@ -535,7 +566,7 @@ QBrush::QBrush(const QGradient &gradient) }; init(QColor(), enum_table[gradient.type()]); - QGradientBrushData *grad = static_cast<QGradientBrushData *>(d); + QGradientBrushData *grad = static_cast<QGradientBrushData *>(d.data()); grad->gradient = gradient; } @@ -545,24 +576,11 @@ QBrush::QBrush(const QGradient &gradient) QBrush::~QBrush() { - if (!d->ref.deref()) - cleanUp(d); } void QBrush::cleanUp(QBrushData *x) { - switch (x->style) { - case Qt::TexturePattern: - delete static_cast<QTexturedBrushData*>(x); - break; - case Qt::LinearGradientPattern: - case Qt::RadialGradientPattern: - case Qt::ConicalGradientPattern: - delete static_cast<QGradientBrushData*>(x); - break; - default: - delete x; - } + QBrushDataPointerHandler::deleteData(x); } @@ -571,38 +589,36 @@ void QBrush::detach(Qt::BrushStyle newStyle) if (newStyle == d->style && d->ref == 1) return; - QBrushData *x; + QScopedPointer<QBrushData> x; switch(newStyle) { case Qt::TexturePattern: { QTexturedBrushData *tbd = new QTexturedBrushData; if (d->style == Qt::TexturePattern) { - QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d); + QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); if (data->m_has_pixmap_texture) tbd->setPixmap(data->pixmap()); else tbd->setImage(data->image()); } - x = tbd; + x.reset(tbd); break; } case Qt::LinearGradientPattern: case Qt::RadialGradientPattern: case Qt::ConicalGradientPattern: - x = new QGradientBrushData; - static_cast<QGradientBrushData *>(x)->gradient = - static_cast<QGradientBrushData *>(d)->gradient; + x.reset(new QGradientBrushData); + static_cast<QGradientBrushData *>(x.data())->gradient = + static_cast<QGradientBrushData *>(d.data())->gradient; break; default: - x = new QBrushData; + x.reset(new QBrushData); break; } x->ref = 1; x->style = newStyle; x->color = d->color; x->transform = d->transform; - if (!d->ref.deref()) - cleanUp(d); - d = x; + d.reset(x.take()); } @@ -615,10 +631,11 @@ void QBrush::detach(Qt::BrushStyle newStyle) QBrush &QBrush::operator=(const QBrush &b) { + if (this == &b) + return *this; + b.d->ref.ref(); - if (!d->ref.deref()) - cleanUp(d); - d = b.d; + d.reset(b.d.data()); return *this; } @@ -713,7 +730,7 @@ QPixmap *QBrush::pixmap() const { if (d->style != Qt::TexturePattern) return 0; - QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d); + QTexturedBrushData *data = static_cast<QTexturedBrushData*>(d.data()); QPixmap &pixmap = data->pixmap(); return pixmap.isNull() ? 0 : &pixmap; } @@ -730,7 +747,7 @@ QPixmap *QBrush::pixmap() const QPixmap QBrush::texture() const { return d->style == Qt::TexturePattern - ? ((QTexturedBrushData*) d)->pixmap() + ? (static_cast<QTexturedBrushData *>(d.data()))->pixmap() : QPixmap(); } @@ -748,7 +765,7 @@ void QBrush::setTexture(const QPixmap &pixmap) { if (!pixmap.isNull()) { detach(Qt::TexturePattern); - QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d); + QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); data->setPixmap(pixmap); } else { detach(Qt::NoBrush); @@ -771,7 +788,7 @@ void QBrush::setTexture(const QPixmap &pixmap) QImage QBrush::textureImage() const { return d->style == Qt::TexturePattern - ? ((QTexturedBrushData *) d)->image() + ? (static_cast<QTexturedBrushData *>(d.data()))->image() : QImage(); } @@ -796,7 +813,7 @@ void QBrush::setTextureImage(const QImage &image) { if (!image.isNull()) { detach(Qt::TexturePattern); - QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d); + QTexturedBrushData *data = static_cast<QTexturedBrushData *>(d.data()); data->setImage(image); } else { detach(Qt::NoBrush); @@ -812,7 +829,7 @@ const QGradient *QBrush::gradient() const if (d->style == Qt::LinearGradientPattern || d->style == Qt::RadialGradientPattern || d->style == Qt::ConicalGradientPattern) { - return &static_cast<const QGradientBrushData *>(d)->gradient; + return &static_cast<const QGradientBrushData *>(d.data())->gradient; } return 0; } @@ -923,16 +940,16 @@ bool QBrush::operator==(const QBrush &b) const if (b.d->style == d->style && b.d->color == d->color) { switch (d->style) { case Qt::TexturePattern: { - QPixmap &us = ((QTexturedBrushData *) d)->pixmap(); - QPixmap &them = ((QTexturedBrushData *) b.d)->pixmap(); + QPixmap &us = (static_cast<QTexturedBrushData *>(d.data()))->pixmap(); + QPixmap &them = (static_cast<QTexturedBrushData *>(b.d.data()))->pixmap(); return ((us.isNull() && them.isNull()) || us.cacheKey() == them.cacheKey()); } case Qt::LinearGradientPattern: case Qt::RadialGradientPattern: case Qt::ConicalGradientPattern: { - QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d); - QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d); + QGradientBrushData *d1 = static_cast<QGradientBrushData *>(d.data()); + QGradientBrushData *d2 = static_cast<QGradientBrushData *>(b.d.data()); return d1->gradient == d2->gradient; } default: diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index d6d0da3..b3aa04d 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -45,6 +45,7 @@ #include <QtCore/qpair.h> #include <QtCore/qpoint.h> #include <QtCore/qvector.h> +#include <QtCore/qscopedpointer.h> #include <QtGui/qcolor.h> #include <QtGui/qmatrix.h> #include <QtGui/qtransform.h> @@ -61,6 +62,7 @@ struct QBrushData; class QPixmap; class QGradient; class QVariant; +struct QBrushDataPointerHandler; class Q_GUI_EXPORT QBrush { @@ -126,13 +128,13 @@ private: friend bool qHasPixmapTexture(const QBrush& brush); void detach(Qt::BrushStyle newStyle); void init(const QColor &color, Qt::BrushStyle bs); - QBrushData *d; + QScopedCustomPointer<QBrushData, QBrushDataPointerHandler> d; void cleanUp(QBrushData *x); public: inline bool isDetached() const; typedef QBrushData * DataPtr; - inline DataPtr &data_ptr() { return d; } + inline DataPtr &data_ptr() { return d.data_ptr(); } }; inline void QBrush::setColor(Qt::GlobalColor acolor) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index ed4dd57..0b5e5bb 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -7426,8 +7426,8 @@ void qt_build_pow_tables() { } #else for (int i=0; i<256; ++i) { - qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / 255.0, smoothing) * 255)); - qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / 255.0, 1 / smoothing) * 255)); + qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / qreal(255), smoothing) * 255)); + qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / qreal(255), 1 / smoothing) * 255)); } #endif diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index 7de1ec4..c5be802 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -713,7 +713,6 @@ QPaintEngine::QPaintEngine(QPaintEnginePrivate &dptr, PaintEngineFeatures caps) */ QPaintEngine::~QPaintEngine() { - delete d_ptr; } /*! diff --git a/src/gui/painting/qpaintengine.h b/src/gui/painting/qpaintengine.h index 520f71f..6f56adb 100644 --- a/src/gui/painting/qpaintengine.h +++ b/src/gui/painting/qpaintengine.h @@ -44,6 +44,7 @@ #include <QtCore/qnamespace.h> #include <QtCore/qobjectdefs.h> +#include <QtCore/qscopedpointer.h> #include <QtGui/qpainter.h> QT_BEGIN_HEADER @@ -239,7 +240,7 @@ protected: uint selfDestruct : 1; uint extended : 1; - QPaintEnginePrivate *d_ptr; + QScopedPointer<QPaintEnginePrivate> d_ptr; private: void setAutoDestruct(bool autoDestr) { selfDestruct = autoDestr; } diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 95b4100..ada3ebf 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -349,6 +349,7 @@ void QRasterPaintEngine::init() #else (unsigned char *) malloc(d->rasterPoolSize); #endif + Q_CHECK_PTR(d->rasterPoolBase); // The antialiasing raster. d->grayRaster = new QT_FT_Raster; @@ -3904,7 +3905,7 @@ static void qt_merge_clip(const QClipData *c1, const QClipData *c2, QClipData *r // find required length int max = qMax(c1_spans[c1_count - 1].x + c1_spans[c1_count - 1].len, - c2_spans[c2_count - 1].x + c2_spans[c2_count - 1].len); + c2_spans[c2_count - 1].x + c2_spans[c2_count - 1].len); buffer.resize(max); memset(buffer.data(), 0, buffer.size() * sizeof(short)); @@ -3958,7 +3959,7 @@ void QRasterPaintEnginePrivate::initializeRasterizer(QSpanData *data) const QClipData *c = clip(); if (c) { const QRect r(QPoint(c->xmin, c->ymin), - QPoint(c->xmax, c->ymax)); + QPoint(c->xmax, c->ymax)); clipRect = clipRect.intersected(r); blend = data->blend; } else { @@ -4066,6 +4067,7 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline, #else (unsigned char *) malloc(rasterPoolSize); #endif + Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal. qt_ft_grays_raster.raster_done(*grayRaster); qt_ft_grays_raster.raster_new(0, grayRaster); @@ -4301,93 +4303,107 @@ void QClipData::initialize() return; m_clipLines = (ClipLine *)calloc(sizeof(ClipLine), clipSpanHeight); - m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan)); - - if (hasRectClip) { - int y = 0; - while (y < ymin) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; - } + Q_CHECK_PTR(m_clipLines); + QT_TRY { + m_spans = (QSpan *)malloc(clipSpanHeight*sizeof(QSpan)); + Q_CHECK_PTR(m_spans); + + QT_TRY { + if (hasRectClip) { + int y = 0; + while (y < ymin) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } - const int len = clipRect.width(); - count = 0; - while (y < ymax) { - QSpan *span = m_spans + count; - span->x = xmin; - span->len = len; - span->y = y; - span->coverage = 255; - ++count; - - m_clipLines[y].spans = span; - m_clipLines[y].count = 1; - ++y; - } + const int len = clipRect.width(); + count = 0; + while (y < ymax) { + QSpan *span = m_spans + count; + span->x = xmin; + span->len = len; + span->y = y; + span->coverage = 255; + ++count; - while (y < clipSpanHeight) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; - } - } else if (hasRegionClip) { + m_clipLines[y].spans = span; + m_clipLines[y].count = 1; + ++y; + } - const QVector<QRect> rects = clipRegion.rects(); - const int numRects = rects.size(); + while (y < clipSpanHeight) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } + } else if (hasRegionClip) { + + const QVector<QRect> rects = clipRegion.rects(); + const int numRects = rects.size(); + + { // resize + const int maxSpans = (ymax - ymin) * numRects; + if (maxSpans > allocated) { + QSpan *newSpans = (QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan)); + Q_CHECK_PTR(newSpans); + m_spans = newSpans; + allocated = maxSpans; + } + } - { // resize - const int maxSpans = (ymax - ymin) * numRects; - if (maxSpans > allocated) { - m_spans = (QSpan *)realloc(m_spans, maxSpans * sizeof(QSpan)); - allocated = maxSpans; - } - } + int y = 0; + int firstInBand = 0; + while (firstInBand < numRects) { + const int currMinY = rects.at(firstInBand).y(); + const int currMaxY = currMinY + rects.at(firstInBand).height(); - int y = 0; - int firstInBand = 0; - while (firstInBand < numRects) { - const int currMinY = rects.at(firstInBand).y(); - const int currMaxY = currMinY + rects.at(firstInBand).height(); + while (y < currMinY) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } - while (y < currMinY) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; - } + int lastInBand = firstInBand; + while (lastInBand + 1 < numRects && rects.at(lastInBand+1).top() == y) + ++lastInBand; - int lastInBand = firstInBand; - while (lastInBand + 1 < numRects && rects.at(lastInBand+1).top() == y) - ++lastInBand; + while (y < currMaxY) { - while (y < currMaxY) { + m_clipLines[y].spans = m_spans + count; + m_clipLines[y].count = lastInBand - firstInBand + 1; - m_clipLines[y].spans = m_spans + count; - m_clipLines[y].count = lastInBand - firstInBand + 1; + for (int r = firstInBand; r <= lastInBand; ++r) { + const QRect &currRect = rects.at(r); + QSpan *span = m_spans + count; + span->x = currRect.x(); + span->len = currRect.width(); + span->y = y; + span->coverage = 255; + ++count; + } + ++y; + } - for (int r = firstInBand; r <= lastInBand; ++r) { - const QRect &currRect = rects.at(r); - QSpan *span = m_spans + count; - span->x = currRect.x(); - span->len = currRect.width(); - span->y = y; - span->coverage = 255; - ++count; + firstInBand = lastInBand + 1; } - ++y; - } - firstInBand = lastInBand + 1; - } + Q_ASSERT(count <= allocated); - Q_ASSERT(count <= allocated); + while (y < clipSpanHeight) { + m_clipLines[y].spans = 0; + m_clipLines[y].count = 0; + ++y; + } - while (y < clipSpanHeight) { - m_clipLines[y].spans = 0; - m_clipLines[y].count = 0; - ++y; + } + } QT_CATCH(...) { + free(m_spans); + QT_RETHROW; } - + } QT_CATCH(...) { + free(m_clipLines); + QT_RETHROW; } } @@ -4764,8 +4780,10 @@ static void qt_span_clip(int count, const QSpan *spans, void *userData) &newspans, newClip->allocated - newClip->count); newClip->count = newspans - newClip->m_spans; if (spans < end) { + QSpan *newSpan = (QSpan *)realloc(newClip->m_spans, newClip->allocated*2*sizeof(QSpan)); + Q_CHECK_PTR(newSpan); + newClip->m_spans = newSpan; newClip->allocated *= 2; - newClip->m_spans = (QSpan *)realloc(newClip->m_spans, newClip->allocated*sizeof(QSpan)); } } } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index cc48d24..0caf13b 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -83,6 +83,21 @@ static const qreal aliasedCoordinateDelta = 0.5 - 0.015625; bool qt_show_painter_debug_output = true; #endif +class QPainterPrivateCleaner +{ +public: + static inline void cleanup(QPainterPrivate *d) + { + delete d; + } + + static inline void reset(QPainterPrivate *&d, QPainterPrivate *other) + { + delete d; + d = other; + } +}; + extern QPixmap qt_pixmapForBrush(int style, bool invert); void qt_format_text(const QFont &font, @@ -259,14 +274,17 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev) // in 99% of all cases). E.g: A renders B which renders C which renders D. sp->d_ptr->d_ptrs_size = 4; sp->d_ptr->d_ptrs = (QPainterPrivate **)malloc(4 * sizeof(QPainterPrivate *)); + Q_CHECK_PTR(sp->d_ptr->d_ptrs); } else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) { // However, to support corner cases we grow the array dynamically if needed. sp->d_ptr->d_ptrs_size <<= 1; const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *); - sp->d_ptr->d_ptrs = (QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize); + QPainterPrivate ** newPointers = (QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize); + Q_CHECK_PTR(newPointers); + sp->d_ptr->d_ptrs = newPointers; } - sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr; - q->d_ptr = sp->d_ptr; + sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data(); + q->d_ptr.data_ptr() = sp->d_ptr.data(); Q_ASSERT(q->d_ptr->state); @@ -315,7 +333,7 @@ void QPainterPrivate::detachPainterPrivate(QPainter *q) d_ptrs[refcount - 1] = 0; q->restore(); - q->d_ptr = original; + q->d_ptr.data_ptr() = original; if (emulationEngine) { extended = emulationEngine->real_engine; @@ -1374,8 +1392,8 @@ void QPainterPrivate::updateState(QPainterState *newState) */ QPainter::QPainter() + : d_ptr(new QPainterPrivate(this)) { - d_ptr = new QPainterPrivate(this); } /*! @@ -1407,7 +1425,7 @@ QPainter::QPainter(QPaintDevice *pd) { Q_ASSERT(pd != 0); if (!QPainterPrivate::attachPainterPrivate(this, pd)) { - d_ptr = new QPainterPrivate(this); + d_ptr.reset(new QPainterPrivate(this)); begin(pd); } Q_ASSERT(d_ptr); @@ -1419,11 +1437,14 @@ QPainter::QPainter(QPaintDevice *pd) QPainter::~QPainter() { d_ptr->inDestructor = true; - if (isActive()) - end(); - else if (d_ptr->refcount > 1) - d_ptr->detachPainterPrivate(this); - + QT_TRY { + if (isActive()) + end(); + else if (d_ptr->refcount > 1) + d_ptr->detachPainterPrivate(this); + } QT_CATCH(...) { + // don't throw anything in the destructor. + } if (d_ptr) { // Make sure we haven't messed things up. Q_ASSERT(d_ptr->inDestructor); @@ -1431,7 +1452,6 @@ QPainter::~QPainter() Q_ASSERT(d_ptr->refcount == 1); if (d_ptr->d_ptrs) free(d_ptr->d_ptrs); - delete d_ptr; } } @@ -7417,8 +7437,21 @@ QPaintDevice *QPainter::redirected(const QPaintDevice *device, QPoint *offset) void qt_painter_removePaintDevice(QPaintDevice *dev) { - QMutexLocker locker(globalRedirectionsMutex()); - if(QPaintDeviceRedirectionList *redirections = globalRedirections()) { + QMutex *mutex = 0; + QT_TRY { + mutex = globalRedirectionsMutex(); + } QT_CATCH(...) { + // ignore the missing mutex, since we could be called from + // a destructor, and destructors shall not throw + } + QMutexLocker locker(mutex); + QPaintDeviceRedirectionList *redirections = 0; + QT_TRY { + redirections = globalRedirections(); + } QT_CATCH(...) { + // do nothing - code below is safe with redirections being 0. + } + if (redirections) { for (int i = 0; i < redirections->size(); ) { if(redirections->at(i) == dev || redirections->at(i).replacement == dev) redirections->removeAt(i); diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index f3df7a3..d8c6980 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -45,6 +45,7 @@ #include <QtCore/qnamespace.h> #include <QtCore/qrect.h> #include <QtCore/qpoint.h> +#include <QtCore/qscopedpointer.h> #include <QtGui/qpixmap.h> #include <QtGui/qimage.h> #include <QtGui/qtextoption.h> @@ -78,6 +79,8 @@ class QTextItem; class QMatrix; class QTransform; +class QPainterPrivateCleaner; + class Q_GUI_EXPORT QPainter { Q_DECLARE_PRIVATE(QPainter) @@ -497,7 +500,7 @@ private: Q_DISABLE_COPY(QPainter) friend class Q3Painter; - QPainterPrivate *d_ptr; + QScopedCustomPointer<QPainterPrivate, QPainterPrivateCleaner> d_ptr; friend class QFontEngine; friend class QFontEngineBox; diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp index 1b2c4e3..12dbc62 100644 --- a/src/gui/painting/qpainterpath.cpp +++ b/src/gui/painting/qpainterpath.cpp @@ -506,10 +506,10 @@ QPainterPath::QPainterPath() \sa operator=() */ QPainterPath::QPainterPath(const QPainterPath &other) - : d_ptr(other.d_ptr) + : d_ptr(other.d_ptr.data()) { - if (d_func()) - d_func()->ref.ref(); + if (d_ptr) + d_ptr->ref.ref(); } /*! @@ -530,9 +530,7 @@ QPainterPath::QPainterPath(const QPointF &startPoint) void QPainterPath::detach_helper() { QPainterPathPrivate *data = new QPainterPathData(*d_func()); - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = data; + d_ptr.reset(data); } /*! @@ -544,9 +542,7 @@ void QPainterPath::ensureData_helper() data->elements.reserve(16); QPainterPath::Element e = { 0, 0, QPainterPath::MoveToElement }; data->elements << e; - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = data; + d_ptr.reset(data); Q_ASSERT(d_ptr != 0); } @@ -563,9 +559,7 @@ QPainterPath &QPainterPath::operator=(const QPainterPath &other) QPainterPathPrivate *data = other.d_func(); if (data) data->ref.ref(); - if (d_ptr && !d_ptr->ref.deref()) - delete d_ptr; - d_ptr = data; + d_ptr.reset(data); } return *this; } @@ -575,8 +569,6 @@ QPainterPath &QPainterPath::operator=(const QPainterPath &other) */ QPainterPath::~QPainterPath() { - if (d_func() && !d_func()->ref.deref()) - delete d_func(); } /*! @@ -2408,7 +2400,6 @@ QPainterPathStroker::QPainterPathStroker() */ QPainterPathStroker::~QPainterPathStroker() { - delete d_ptr; } diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h index 6cd2af8..0513593 100644 --- a/src/gui/painting/qpainterpath.h +++ b/src/gui/painting/qpainterpath.h @@ -47,6 +47,7 @@ #include <QtCore/qrect.h> #include <QtCore/qline.h> #include <QtCore/qvector.h> +#include <QtCore/qscopedpointer.h> QT_BEGIN_HEADER @@ -195,7 +196,7 @@ public: QPainterPath &operator-=(const QPainterPath &other); private: - QPainterPathPrivate *d_ptr; + QScopedSharedPointer<QPainterPathPrivate> d_ptr; inline void ensureData() { if (!d_ptr) ensureData_helper(); } void ensureData_helper(); @@ -205,7 +206,7 @@ private: void computeBoundingRect() const; void computeControlPointRect() const; - QPainterPathData *d_func() const { return reinterpret_cast<QPainterPathData *>(d_ptr); } + QPainterPathData *d_func() const { return reinterpret_cast<QPainterPathData *>(d_ptr.data()); } friend class QPainterPathData; friend class QPainterPathStroker; @@ -229,6 +230,8 @@ public: friend class QPainterPathStrokerPrivate; friend class QMatrix; friend class QTransform; + friend class QScopedSharedPointer<QPainterPathPrivate>; + friend class QScopedSharedPointerHandler<QPainterPathPrivate>; #ifndef QT_NO_DATASTREAM friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &); friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &); @@ -279,7 +282,7 @@ public: private: friend class QX11PaintEngine; - QPainterPathStrokerPrivate *d_ptr; + QScopedPointer<QPainterPathStrokerPrivate> d_ptr; }; inline void QPainterPath::moveTo(qreal x, qreal y) diff --git a/src/gui/painting/qprinter.cpp b/src/gui/painting/qprinter.cpp index ed72077..ba6baa6 100644 --- a/src/gui/painting/qprinter.cpp +++ b/src/gui/painting/qprinter.cpp @@ -712,7 +712,6 @@ QPrinter::~QPrinter() #ifndef QT_NO_PRINTPREVIEWWIDGET delete d->previewEngine; #endif - delete d; } /*! diff --git a/src/gui/painting/qprinter.h b/src/gui/painting/qprinter.h index 949c8f9..24e867b 100644 --- a/src/gui/painting/qprinter.h +++ b/src/gui/painting/qprinter.h @@ -42,8 +42,9 @@ #ifndef QPRINTER_H #define QPRINTER_H -#include <QtGui/qpaintdevice.h> #include <QtCore/qstring.h> +#include <QtCore/qscopedpointer.h> +#include <QtGui/qpaintdevice.h> QT_BEGIN_HEADER @@ -288,7 +289,7 @@ private: Q_DISABLE_COPY(QPrinter) - QPrinterPrivate *d_ptr; + QScopedPointer<QPrinterPrivate> d_ptr; friend class QPrintDialogPrivate; friend class QAbstractPrintDialog; diff --git a/src/gui/painting/qprinterinfo.h b/src/gui/painting/qprinterinfo.h index b826306..d188d73 100644 --- a/src/gui/painting/qprinterinfo.h +++ b/src/gui/painting/qprinterinfo.h @@ -53,6 +53,7 @@ QT_MODULE(Gui) #ifndef QT_NO_PRINTER class QPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup; class Q_GUI_EXPORT QPrinterInfo { Q_DECLARE_PRIVATE(QPrinterInfo) @@ -76,7 +77,7 @@ public: private: QPrinterInfo(const QString& name); - QPrinterInfoPrivate* d_ptr; + QScopedCustomPointer<QPrinterInfoPrivate, QPrinterInfoPrivateCleanup> d_ptr; }; #endif // QT_NO_PRINTER diff --git a/src/gui/painting/qprinterinfo_mac.cpp b/src/gui/painting/qprinterinfo_mac.cpp index ecd4b5b..ae689f4 100644 --- a/src/gui/painting/qprinterinfo_mac.cpp +++ b/src/gui/painting/qprinterinfo_mac.cpp @@ -65,6 +65,22 @@ private: static QPrinterInfoPrivate nullQPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup +{ +public: + static inline void cleanup(QPrinterInfoPrivate *d) + { + if (d != &nullQPrinterInfoPrivate) + delete d; + } + + static inline void reset(QPrinterInfoPrivate *&d, QPrinterInfoPrivate *other) + { + cleanup(d); + d = other; + } +}; + extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size); ///////////////////////////////////////////////////////////////////////////// @@ -106,8 +122,8 @@ QPrinterInfo QPrinterInfo::defaultPrinter(){ ///////////////////////////////////////////////////////////////////////////// QPrinterInfo::QPrinterInfo(const QPrinter& prn) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; QList<QPrinterInfo> list = availablePrinters(); for (int c = 0; c < list.size(); ++c) { if (prn.printerName() == list[c].printerName()) { @@ -115,39 +131,33 @@ QPrinterInfo::QPrinterInfo(const QPrinter& prn) return; } } - - *this = QPrinterInfo(); } QPrinterInfo::~QPrinterInfo() { - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; } QPrinterInfo::QPrinterInfo() + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; } QPrinterInfo::QPrinterInfo(const QString& name) + : d_ptr(new QPrinterInfoPrivate(name)) { - d_ptr = new QPrinterInfoPrivate(name); d_ptr->q_ptr = this; } QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; *this = src; } QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) { Q_ASSERT(d_ptr); - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; - d_ptr = new QPrinterInfoPrivate(*src.d_ptr); + d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); d_ptr->q_ptr = this; return *this; } diff --git a/src/gui/painting/qprinterinfo_unix.cpp b/src/gui/painting/qprinterinfo_unix.cpp index 0f33ea7..55e3226 100644 --- a/src/gui/painting/qprinterinfo_unix.cpp +++ b/src/gui/painting/qprinterinfo_unix.cpp @@ -82,6 +82,22 @@ private: static QPrinterInfoPrivate nullQPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup +{ +public: + static inline void cleanup(QPrinterInfoPrivate *d) + { + if (d != &nullQPrinterInfoPrivate) + delete d; + } + + static inline void reset(QPrinterInfoPrivate *&d, QPrinterInfoPrivate *other) + { + cleanup(d); + d = other; + } +}; + ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// @@ -867,19 +883,19 @@ QPrinterInfo QPrinterInfo::defaultPrinter() } QPrinterInfo::QPrinterInfo() + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; } QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; *this = src; } QPrinterInfo::QPrinterInfo(const QPrinter& printer) + : d_ptr(new QPrinterInfoPrivate(printer.printerName())) { - d_ptr = new QPrinterInfoPrivate(printer.printerName()); Q_D(QPrinterInfo); d->q_ptr = this; @@ -929,28 +945,23 @@ QPrinterInfo::QPrinterInfo(const QPrinter& printer) #endif // Printer not found. - delete d; - d_ptr = &nullQPrinterInfoPrivate; + d_ptr.reset(&nullQPrinterInfoPrivate); } QPrinterInfo::QPrinterInfo(const QString& name) + : d_ptr(new QPrinterInfoPrivate(name)) { - d_ptr = new QPrinterInfoPrivate(name); d_ptr->q_ptr = this; } QPrinterInfo::~QPrinterInfo() { - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; } QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) { Q_ASSERT(d_ptr); - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; - d_ptr = new QPrinterInfoPrivate(*src.d_ptr); + d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); d_ptr->q_ptr = this; return *this; } diff --git a/src/gui/painting/qprinterinfo_win.cpp b/src/gui/painting/qprinterinfo_win.cpp index 7cd3cf3..7607391 100644 --- a/src/gui/painting/qprinterinfo_win.cpp +++ b/src/gui/painting/qprinterinfo_win.cpp @@ -69,6 +69,22 @@ private: static QPrinterInfoPrivate nullQPrinterInfoPrivate; +class QPrinterInfoPrivateCleanup +{ +public: + static inline void cleanup(QPrinterInfoPrivate *d) + { + if (d != &nullQPrinterInfoPrivate) + delete d; + } + + static inline void reset(QPrinterInfoPrivate *&d, QPrinterInfoPrivate *other) + { + cleanup(d); + d = other; + } +}; + ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// @@ -155,25 +171,25 @@ QPrinterInfo QPrinterInfo::defaultPrinter() ///////////////////////////////////////////////////////////////////////////// QPrinterInfo::QPrinterInfo() + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; } QPrinterInfo::QPrinterInfo(const QString& name) + : d_ptr(new QPrinterInfoPrivate(name)) { - d_ptr = new QPrinterInfoPrivate(name); d_ptr->q_ptr = this; } QPrinterInfo::QPrinterInfo(const QPrinterInfo& src) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; *this = src; } QPrinterInfo::QPrinterInfo(const QPrinter& prn) + : d_ptr(&nullQPrinterInfoPrivate) { - d_ptr = &nullQPrinterInfoPrivate; QList<QPrinterInfo> list = availablePrinters(); for (int c = 0; c < list.size(); ++c) { if (prn.printerName() == list[c].printerName()) { @@ -187,16 +203,12 @@ QPrinterInfo::QPrinterInfo(const QPrinter& prn) QPrinterInfo::~QPrinterInfo() { - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; } QPrinterInfo& QPrinterInfo::operator=(const QPrinterInfo& src) { Q_ASSERT(d_ptr); - if (d_ptr != &nullQPrinterInfoPrivate) - delete d_ptr; - d_ptr = new QPrinterInfoPrivate(*src.d_ptr); + d_ptr.reset(new QPrinterInfoPrivate(*src.d_ptr)); d_ptr->q_ptr = this; return *this; } diff --git a/src/gui/painting/qrasterizer.cpp b/src/gui/painting/qrasterizer.cpp index 583885c..3c06bb4 100644 --- a/src/gui/painting/qrasterizer.cpp +++ b/src/gui/painting/qrasterizer.cpp @@ -436,8 +436,11 @@ void QScanConverter::end() inline void QScanConverter::allocate(int size) { if (m_alloc < size) { - m_alloc = qMax(size, 2 * m_alloc); - m_intersections = (Intersection *)realloc(m_intersections, m_alloc * sizeof(Intersection)); + int newAlloc = qMax(size, 2 * m_alloc); + Intersection *newIntersections = (Intersection *)realloc(m_intersections, newAlloc * sizeof(Intersection)); + Q_CHECK_PTR(newIntersections); + m_alloc = newAlloc; + m_intersections = newIntersections; } } diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index c88af7c..65964de 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -3167,6 +3167,7 @@ static void InsertEdgeInET(EdgeTable *ET, EdgeTableEntry *ETE, int scanline, { tmpSLLBlock = (ScanLineListBlock *)malloc(sizeof(ScanLineListBlock)); + Q_CHECK_PTR(tmpSLLBlock); (*SLLBlock)->next = tmpSLLBlock; tmpSLLBlock->next = (ScanLineListBlock *)NULL; *SLLBlock = tmpSLLBlock; @@ -3553,6 +3554,8 @@ static void PtsToRegion(register int numFullPtBlocks, register int iCurPtBlock, * Scan converts a polygon by returning a run-length * encoding of the resultant bitmap -- the run-length * encoding is in the form of an array of rectangles. + * + * Can return 0 in case of errors. */ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) //Point *Pts; /* the pts */ @@ -3624,75 +3627,28 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) } - if (rule == EvenOddRule) { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; ++y) { - - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - + QT_TRY { + if (rule == EvenOddRule) { /* - * for each active edge + * for each scanline */ - while (pAET) { - pts->setX(pAET->bres.minor_axis); - pts->setY(y); - ++pts; - ++iPts; + for (y = ET.ymin; y < ET.ymax; ++y) { /* - * send out the buffer + * Add a new edge to the active edge table when we + * get to the next edge. */ - if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK)); - tmpPtBlock->pts = reinterpret_cast<QPoint *>(tmpPtBlock->data); - curPtBlock->next = tmpPtBlock; - curPtBlock = tmpPtBlock; - pts = curPtBlock->pts; - ++numFullPtBlocks; - iPts = 0; + if (pSLL && y == pSLL->scanline) { + loadAET(&AET, pSLL->edgelist); + pSLL = pSLL->next; } - EVALUATEEDGEEVENODD(pAET, pPrevAET, y) - } - InsertionSort(&AET); - } - } else { - /* - * for each scanline - */ - for (y = ET.ymin; y < ET.ymax; ++y) { - /* - * Add a new edge to the active edge table when we - * get to the next edge. - */ - if (pSLL && y == pSLL->scanline) { - loadAET(&AET, pSLL->edgelist); - computeWAET(&AET); - pSLL = pSLL->next; - } - pPrevAET = &AET; - pAET = AET.next; - pWETE = pAET; + pPrevAET = &AET; + pAET = AET.next; - /* - * for each active edge - */ - while (pAET) { /* - * add to the buffer only those edges that - * are in the Winding active edge table. + * for each active edge */ - if (pWETE == pAET) { + while (pAET) { pts->setX(pAET->bres.minor_axis); pts->setY(y); ++pts; @@ -3702,7 +3658,8 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) * send out the buffer */ if (iPts == NUMPTSTOBUFFER) { - tmpPtBlock = static_cast<POINTBLOCK *>(malloc(sizeof(POINTBLOCK))); + tmpPtBlock = (POINTBLOCK *)malloc(sizeof(POINTBLOCK)); + Q_CHECK_PTR(tmpPtBlock); tmpPtBlock->pts = reinterpret_cast<QPoint *>(tmpPtBlock->data); curPtBlock->next = tmpPtBlock; curPtBlock = tmpPtBlock; @@ -3710,21 +3667,81 @@ static QRegionPrivate *PolygonRegion(const QPoint *Pts, int Count, int rule) ++numFullPtBlocks; iPts = 0; } - pWETE = pWETE->nextWETE; + EVALUATEEDGEEVENODD(pAET, pPrevAET, y) } - EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) + InsertionSort(&AET); } - + } else { /* - * recompute the winding active edge table if - * we just resorted or have exited an edge. + * for each scanline */ - if (InsertionSort(&AET) || fixWAET) { - computeWAET(&AET); - fixWAET = false; + for (y = ET.ymin; y < ET.ymax; ++y) { + /* + * Add a new edge to the active edge table when we + * get to the next edge. + */ + if (pSLL && y == pSLL->scanline) { + loadAET(&AET, pSLL->edgelist); + computeWAET(&AET); + pSLL = pSLL->next; + } + pPrevAET = &AET; + pAET = AET.next; + pWETE = pAET; + + /* + * for each active edge + */ + while (pAET) { + /* + * add to the buffer only those edges that + * are in the Winding active edge table. + */ + if (pWETE == pAET) { + pts->setX(pAET->bres.minor_axis); + pts->setY(y); + ++pts; + ++iPts; + + /* + * send out the buffer + */ + if (iPts == NUMPTSTOBUFFER) { + tmpPtBlock = static_cast<POINTBLOCK *>(malloc(sizeof(POINTBLOCK))); + tmpPtBlock->pts = reinterpret_cast<QPoint *>(tmpPtBlock->data); + curPtBlock->next = tmpPtBlock; + curPtBlock = tmpPtBlock; + pts = curPtBlock->pts; + ++numFullPtBlocks; + iPts = 0; + } + pWETE = pWETE->nextWETE; + } + EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) + } + + /* + * recompute the winding active edge table if + * we just resorted or have exited an edge. + */ + if (InsertionSort(&AET) || fixWAET) { + computeWAET(&AET); + fixWAET = false; + } } } + } QT_CATCH(...) { + FreeStorage(SLLBlock.next); + PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region); + for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) { + tmpPtBlock = curPtBlock->next; + free(curPtBlock); + curPtBlock = tmpPtBlock; + } + free(pETEs); + return 0; // this function returns 0 in case of an error } + FreeStorage(SLLBlock.next); PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, region); for (curPtBlock = FirstPtBlock.next; --numFullPtBlocks >= 0;) { @@ -3923,11 +3940,10 @@ QRegion &QRegion::operator=(const QRegion &r) /*! \internal */ - QRegion QRegion::copy() const { QRegion r; - QRegionData *x = new QRegionData; + QScopedPointer<QRegionData> x(new QRegionData); x->ref = 1; #if defined(Q_WS_X11) x->rgn = 0; @@ -3941,7 +3957,7 @@ QRegion QRegion::copy() const x->qt_rgn = new QRegionPrivate; if (!r.d->ref.deref()) cleanUp(r.d); - r.d = x; + r.d = x.take(); return r; } diff --git a/src/gui/painting/qwindowsurface_raster.cpp b/src/gui/painting/qwindowsurface_raster.cpp index 0a6a04e..97178a6 100644 --- a/src/gui/painting/qwindowsurface_raster.cpp +++ b/src/gui/painting/qwindowsurface_raster.cpp @@ -115,8 +115,6 @@ QRasterWindowSurface::~QRasterWindowSurface() #endif if (d_ptr->image) delete d_ptr->image; - - delete d_ptr; } diff --git a/src/gui/painting/qwindowsurface_raster_p.h b/src/gui/painting/qwindowsurface_raster_p.h index 2a3535f..c10bec3 100644 --- a/src/gui/painting/qwindowsurface_raster_p.h +++ b/src/gui/painting/qwindowsurface_raster_p.h @@ -112,7 +112,7 @@ public: private: void prepareBuffer(QImage::Format format, QWidget *widget); Q_DECLARE_PRIVATE(QRasterWindowSurface) - QRasterWindowSurfacePrivate *d_ptr; + QScopedPointer<QRasterWindowSurfacePrivate> d_ptr; }; QT_END_NAMESPACE |