diff options
author | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-04-29 11:29:06 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-04-29 11:30:43 (GMT) |
commit | 7fac03fc111f0c5938eff80f96d25c03c70c4040 (patch) | |
tree | 48748aa6cd8cc53ac698994d643d604146a9e794 /src | |
parent | ae16f6c59a009a508c1224b5dc02752ada0ce61a (diff) | |
download | Qt-7fac03fc111f0c5938eff80f96d25c03c70c4040.zip Qt-7fac03fc111f0c5938eff80f96d25c03c70c4040.tar.gz Qt-7fac03fc111f0c5938eff80f96d25c03c70c4040.tar.bz2 |
Fixed a leak in QTextDocument::print().
Also fixed a typo in the QScopedPointer docs.
Task-number: QTBUG-10301
Reviewed-by: Kim
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qscopedpointer.cpp | 4 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 9 |
2 files changed, 5 insertions, 8 deletions
diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index e7dd769..b06112d 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE called resource acquisition is initialization(RAII). QScopedPointer guarantees that the object pointed to will get deleted when - the current scope dissapears. + the current scope disappears. Consider this function which does heap allocations, and have various exit points: @@ -227,7 +227,7 @@ QT_BEGIN_NAMESPACE /*! \class QScopedArrayPointer - + \brief The QScopedArrayPointer class stores a pointer to a dynamically allocated array of objects, and deletes it upon destruction. diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index f5d322a..1677ee6 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -1679,7 +1679,7 @@ void QTextDocument::print(QPrinter *printer) const return; const QTextDocument *doc = this; - QTextDocument *clonedDoc = 0; + QScopedPointer<QTextDocument> clonedDoc; (void)doc->documentLayout(); // make sure that there is a layout QRectF body = QRectF(QPointF(0, 0), d->pageSize); @@ -1712,7 +1712,7 @@ void QTextDocument::print(QPrinter *printer) const printerPageSize.height() / scaledPageSize.height()); } else { doc = clone(const_cast<QTextDocument *>(this)); - clonedDoc = const_cast<QTextDocument *>(doc); + clonedDoc.reset(const_cast<QTextDocument *>(doc)); for (QTextBlock srcBlock = firstBlock(), dstBlock = clonedDoc->firstBlock(); srcBlock.isValid() && dstBlock.isValid(); @@ -1787,7 +1787,7 @@ void QTextDocument::print(QPrinter *printer) const for (int j = 0; j < pageCopies; ++j) { if (printer->printerState() == QPrinter::Aborted || printer->printerState() == QPrinter::Error) - goto UserCanceled; + return; printPage(page, &p, doc, body, pageNumberPos); if (j < pageCopies - 1) printer->newPage(); @@ -1807,9 +1807,6 @@ void QTextDocument::print(QPrinter *printer) const if ( i < docCopies - 1) printer->newPage(); } - -UserCanceled: - delete clonedDoc; } #endif |