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>
This commit is contained in:
Andy Shaw 2012-03-06 10:39:34 +01:00 committed by Qt by Nokia
parent 13c57d0f68
commit 0850b5d76a

View File

@ -246,16 +246,32 @@ QList<QByteArray> QFontEngineQPF::cleanUpAfterClientCrash(const QList<int> &cras
int fd = QT_OPEN(fileName.constData(), O_RDONLY, 0); int fd = QT_OPEN(fileName.constData(), O_RDONLY, 0);
if (fd >= 0) { if (fd >= 0) {
void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0); QT_STATBUF st;
if (header && header != MAP_FAILED) { int nDataSize = 0;
quint32 lockValue = reinterpret_cast<QFontEngineQPF::Header *>(header)->lock; if (QT_FSTAT(fd, &st)) {
#if defined(DEBUG_FONTENGINE)
qDebug() << "stat failed! " << fileName;
#endif
} else {
nDataSize = st.st_size;
}
if (lockValue && crashedClientIds.contains(lockValue)) { if (nDataSize >= (int)sizeof(QFontEngineQPF::Header)) {
removedFonts.append(fileName); void *header = ::mmap(0, sizeof(QFontEngineQPF::Header), PROT_READ, MAP_SHARED, fd, 0);
QFile::remove(QFile::decodeName(fileName)); if (header && header != MAP_FAILED) {
quint32 lockValue = reinterpret_cast<QFontEngineQPF::Header *>(header)->lock;
if (lockValue && crashedClientIds.contains(lockValue)) {
removedFonts.append(fileName);
QFile::remove(QFile::decodeName(fileName));
}
::munmap(header, sizeof(QFontEngineQPF::Header));
} }
} else {
::munmap(header, sizeof(QFontEngineQPF::Header)); #if defined(DEBUG_FONTENGINE)
qDebug() << "Unsufficient header data in QSF file " << fileName;
#endif
} }
QT_CLOSE(fd); QT_CLOSE(fd);
} }
@ -363,6 +379,7 @@ QFontEngineQPF::QFontEngineQPF(const QFontDef &def, int fileDescriptor, QFontEng
#if defined(DEBUG_FONTENGINE) #if defined(DEBUG_FONTENGINE)
qErrnoWarning(errno, "QFontEngineQPF: write() failed for %s", encodedName.constData()); qErrnoWarning(errno, "QFontEngineQPF: write() failed for %s", encodedName.constData());
#endif #endif
QFile::remove(fileName);
return; return;
} }
} else { } else {