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/image | |
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/image')
-rw-r--r-- | src/gui/image/qimage.cpp | 17 | ||||
-rw-r--r-- | src/gui/image/qimageiohandler.cpp | 1 | ||||
-rw-r--r-- | src/gui/image/qimageiohandler.h | 3 | ||||
-rw-r--r-- | src/gui/image/qpicture.cpp | 17 | ||||
-rw-r--r-- | src/gui/image/qpicture.h | 4 | ||||
-rw-r--r-- | src/gui/image/qpicture_p.h | 2 | ||||
-rw-r--r-- | src/gui/image/qpixmap_s60.cpp | 1 | ||||
-rw-r--r-- | src/gui/image/qpixmapcache.cpp | 7 |
8 files changed, 31 insertions, 21 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 70d4e2c..34ad99c 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -185,6 +185,13 @@ static int depthForFormat(QImage::Format format) return depth; } +/*! \fn QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) + + \internal + + Creates a new image data. + Returns 0 if invalid parameters are give or anything else failed. +*/ QImageData * QImageData::create(const QSize &size, QImage::Format format, int numColors) { if (!size.isValid() || numColors < 0 || format == QImage::Format_Invalid) @@ -223,7 +230,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu || INT_MAX/sizeof(uchar *) < uint(height)) return 0; - QImageData *d = new QImageData; + QScopedPointer<QImageData> d(new QImageData); d->colortable.resize(numColors); if (depth == 1) { d->colortable[0] = QColor(Qt::black).rgba(); @@ -246,12 +253,11 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format, int nu d->data = (uchar *)malloc(d->nbytes); if (!d->data) { - delete d; return 0; } d->ref.ref(); - return d; + return d.take(); } @@ -1621,6 +1627,7 @@ int QImage::numColors() const /*! Returns a pointer to the scanline pointer table. This is the beginning of the data block for the image. + Returns 0 in case of an error. Use the bits() or scanLine() function instead. */ @@ -1636,6 +1643,8 @@ uchar **QImage::jumpTable() if (!d->jumptable) { d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *)); + if (!d->jumptable) + return 0; uchar *data = d->data; int height = d->height; uchar **p = d->jumptable; @@ -1656,6 +1665,8 @@ const uchar * const *QImage::jumpTable() const return 0; if (!d->jumptable) { d->jumptable = (uchar **)malloc(d->height*sizeof(uchar *)); + if (!d->jumptable) + return 0; uchar *data = d->data; int height = d->height; uchar **p = d->jumptable; diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp index a47c69e..f432f87 100644 --- a/src/gui/image/qimageiohandler.cpp +++ b/src/gui/image/qimageiohandler.cpp @@ -272,7 +272,6 @@ QImageIOHandler::QImageIOHandler(QImageIOHandlerPrivate &dd) */ QImageIOHandler::~QImageIOHandler() { - delete d_ptr; } /*! diff --git a/src/gui/image/qimageiohandler.h b/src/gui/image/qimageiohandler.h index 3b654f3..34de715 100644 --- a/src/gui/image/qimageiohandler.h +++ b/src/gui/image/qimageiohandler.h @@ -44,6 +44,7 @@ #include <QtCore/qplugin.h> #include <QtCore/qfactoryinterface.h> +#include <QtCore/qscopedpointer.h> QT_BEGIN_HEADER @@ -109,7 +110,7 @@ public: protected: QImageIOHandler(QImageIOHandlerPrivate &dd); - QImageIOHandlerPrivate *d_ptr; + QScopedPointer<QImageIOHandlerPrivate> d_ptr; private: Q_DISABLE_COPY(QImageIOHandler) }; diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 92023e0..8528173 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -132,7 +132,6 @@ QPicture::QPicture(int formatVersion) { Q_D(QPicture); d_ptr->q_ptr = this; - d->paintEngine = 0; if (formatVersion == 0) qWarning("QPicture: invalid format version 0"); @@ -155,7 +154,7 @@ QPicture::QPicture(int formatVersion) */ QPicture::QPicture(const QPicture &pic) - : QPaintDevice(), d_ptr(pic.d_ptr) + : QPaintDevice(), d_ptr(pic.d_ptr.data()) { d_func()->ref.ref(); } @@ -173,10 +172,6 @@ QPicture::QPicture(QPicturePrivate &dptr) */ QPicture::~QPicture() { - if (!d_func()->ref.deref()) { - delete d_func()->paintEngine; - delete d_func(); - } } /*! @@ -1030,9 +1025,7 @@ void QPicture::detach_helper() x->formatMinor = d->formatMinor; x->brect = d->brect; x->override_rect = d->override_rect; - if (!d->ref.deref()) - delete d; - d_ptr = x; + d_ptr.reset(x); } /*! @@ -1041,7 +1034,7 @@ void QPicture::detach_helper() */ QPicture& QPicture::operator=(const QPicture &p) { - qAtomicAssign<QPicturePrivate>(d_ptr, p.d_ptr); + d_ptr.assign(p.d_ptr.data()); return *this; } @@ -1135,8 +1128,8 @@ bool QPicturePrivate::checkFormat() QPaintEngine *QPicture::paintEngine() const { if (!d_func()->paintEngine) - const_cast<QPicture*>(this)->d_func()->paintEngine = new QPicturePaintEngine; - return d_func()->paintEngine; + const_cast<QPicture*>(this)->d_func()->paintEngine.reset(new QPicturePaintEngine); + return d_func()->paintEngine.data(); } /***************************************************************************** diff --git a/src/gui/image/qpicture.h b/src/gui/image/qpicture.h index fe86e8d..7de1f79 100644 --- a/src/gui/image/qpicture.h +++ b/src/gui/image/qpicture.h @@ -106,7 +106,7 @@ private: bool exec(QPainter *p, QDataStream &ds, int i); void detach_helper(); - QPicturePrivate *d_ptr; + QScopedSharedPointer<QPicturePrivate> d_ptr; friend class QPicturePaintEngine; friend class Q3Picture; friend class QAlphaPaintEngine; @@ -114,7 +114,7 @@ private: public: typedef QPicturePrivate* DataPtr; - inline DataPtr &data_ptr() { return d_ptr; } + inline DataPtr &data_ptr() { return d_ptr.data_ptr(); } }; Q_DECLARE_SHARED(QPicture) diff --git a/src/gui/image/qpicture_p.h b/src/gui/image/qpicture_p.h index a3fd34f..e0c3117 100644 --- a/src/gui/image/qpicture_p.h +++ b/src/gui/image/qpicture_p.h @@ -156,7 +156,7 @@ public: int formatMinor; QRect brect; QRect override_rect; - QPaintEngine *paintEngine; + QScopedPointer<QPaintEngine> paintEngine; bool in_memory_only; QList<QImage> image_list; QList<QPixmap> pixmap_list; diff --git a/src/gui/image/qpixmap_s60.cpp b/src/gui/image/qpixmap_s60.cpp index 3ea50ff..132e26e 100644 --- a/src/gui/image/qpixmap_s60.cpp +++ b/src/gui/image/qpixmap_s60.cpp @@ -38,6 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <exception> #include <w32std.h> #include <fbs.h> diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index c9973d0..4f71e09 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -323,7 +323,12 @@ void QPixmapCache::remove(const QString &key) void QPixmapCache::clear() { - pm_cache()->clear(); + QT_TRY { + pm_cache()->clear(); + } QT_CATCH(const std::bad_alloc &) { + // if we ran out of memory during pm_cache(), it's no leak, + // so just ignore it. + } } QT_END_NAMESPACE |