diff options
author | Andy Shaw <andy.shaw@digia.com> | 2012-03-06 10:39:34 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-12 23:29:37 +0100 |
commit | 0850b5d76a242abe5beef05e2566957b695099a8 (patch) | |
tree | 33f7ff591d9c0e0306b4d51b5ea0ac8c6c3b9124 /src | |
parent | 13c57d0f68cffb139311e8e22a074099eb28a88f (diff) |
Cleanup after the qsf cache file if it fails to be written to
It is possible that although a qsf cache file could be opened that it
could not be written to, therefore it should clean up after itself in
these cases so that it does not cause a problem later on.
Task-number: QTBUG-24122
Change-Id: I1999759837607657ddc3f967eeda370ce9991a16
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qfontengine_qpf.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/gui/text/qfontengine_qpf.cpp b/src/gui/text/qfontengine_qpf.cpp index fb898a850f..64596ebaf5 100644 --- a/src/gui/text/qfontengine_qpf.cpp +++ b/src/gui/text/qfontengine_qpf.cpp @@ -246,16 +246,32 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras int fd = QT_OPEN(fileName.constData(), O_RDONLY, 0); if (fd >= 0) { - void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0); - if (header && header != MAP_FAILED) { - quint32 lockValue = reinterpret_cast<QFontEngineQPF::Header *>(header)->lock; + QT_STATBUF st; + int nDataSize = 0; + if (QT_FSTAT(fd, &st)) { +#if defined(DEBUG_FONTENGINE) + qDebug() << "stat failed! " << fileName; +#endif + } else { + nDataSize = st.st_size; + } - if (lockValue && crashedClientIds.contains(lockValue)) { - removedFonts.append(fileName); - QFile::remove(QFile::decodeName(fileName)); - } + if (nDataSize >= (int)sizeof(QFontEngineQPF::Header)) { + void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0); + if (header && header != MAP_FAILED) { + quint32 lockValue = reinterpret_cast<QFontEngineQPF::Header *>(header)->lock; - ::munmap(header, sizeof(QFontEngineQPF::Header)); + if (lockValue && crashedClientIds.contains(lockValue)) { + removedFonts.append(fileName); + QFile::remove(QFile::decodeName(fileName)); + } + + ::munmap(header, sizeof(QFontEngineQPF::Header)); + } + } else { +#if defined(DEBUG_FONTENGINE) + qDebug() << "Unsufficient header data in QSF file " << fileName; +#endif } QT_CLOSE(fd); } @@ -363,6 +379,7 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng #if defined(DEBUG_FONTENGINE) qErrnoWarning(errno, "QFontEngineQPF: write() failed for %s", encodedName.constData()); #endif + QFile::remove(fileName); return; } } else { |