forked from qt-creator/qt-creator
qmake: fix file id mapping lifetime management, take 2
turns out that ref-counting the vfs class is insufficient, as now the
ProFile cache (which expires after a timeout) could outlive all VFS
instances and thus refer to ids which were discarded and later re-used.
to avoid this, we let the cache instance hold a reference to the vfs
class.
amends d03fb3506
.
Task-number: QTCREATORBUG-20524
Change-Id: Idd4478ffc1c2405b3b83df32fba45b1f687f6a18
Reviewed-by: Robert Loehning <robert.loehning@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -42,11 +42,17 @@ QT_BEGIN_NAMESPACE
|
|||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
ProFileCache::ProFileCache()
|
||||||
|
{
|
||||||
|
QMakeVfs::ref();
|
||||||
|
}
|
||||||
|
|
||||||
ProFileCache::~ProFileCache()
|
ProFileCache::~ProFileCache()
|
||||||
{
|
{
|
||||||
foreach (const Entry &ent, parsed_files)
|
foreach (const Entry &ent, parsed_files)
|
||||||
if (ent.pro)
|
if (ent.pro)
|
||||||
ent.pro->deref();
|
ent.pro->deref();
|
||||||
|
QMakeVfs::deref();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProFileCache::discardFile(const QString &fileName, QMakeVfs *vfs)
|
void ProFileCache::discardFile(const QString &fileName, QMakeVfs *vfs)
|
||||||
|
@@ -197,7 +197,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QMakeParser::ParseFlags)
|
|||||||
class QMAKE_EXPORT ProFileCache
|
class QMAKE_EXPORT ProFileCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProFileCache() {}
|
ProFileCache();
|
||||||
~ProFileCache();
|
~ProFileCache();
|
||||||
|
|
||||||
void discardFile(int id);
|
void discardFile(int id);
|
||||||
|
@@ -49,13 +49,23 @@ QMakeVfs::QMakeVfs()
|
|||||||
#ifndef QT_NO_TEXTCODEC
|
#ifndef QT_NO_TEXTCODEC
|
||||||
m_textCodec = 0;
|
m_textCodec = 0;
|
||||||
#endif
|
#endif
|
||||||
|
ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
QMakeVfs::~QMakeVfs()
|
||||||
|
{
|
||||||
|
deref();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QMakeVfs::ref()
|
||||||
|
{
|
||||||
#ifdef PROEVALUATOR_THREAD_SAFE
|
#ifdef PROEVALUATOR_THREAD_SAFE
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
#endif
|
#endif
|
||||||
++s_refCount;
|
++s_refCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMakeVfs::~QMakeVfs()
|
void QMakeVfs::deref()
|
||||||
{
|
{
|
||||||
#ifdef PROEVALUATOR_THREAD_SAFE
|
#ifdef PROEVALUATOR_THREAD_SAFE
|
||||||
QMutexLocker locker(&s_mutex);
|
QMutexLocker locker(&s_mutex);
|
||||||
@@ -67,7 +77,6 @@ QMakeVfs::~QMakeVfs()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef PROPARSER_THREAD_SAFE
|
#ifdef PROPARSER_THREAD_SAFE
|
||||||
QMutex QMakeVfs::s_mutex;
|
QMutex QMakeVfs::s_mutex;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -74,6 +74,9 @@ public:
|
|||||||
QMakeVfs();
|
QMakeVfs();
|
||||||
~QMakeVfs();
|
~QMakeVfs();
|
||||||
|
|
||||||
|
static void ref();
|
||||||
|
static void deref();
|
||||||
|
|
||||||
int idForFileName(const QString &fn, VfsFlags flags);
|
int idForFileName(const QString &fn, VfsFlags flags);
|
||||||
QString fileNameForId(int id);
|
QString fileNameForId(int id);
|
||||||
bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr);
|
bool writeFile(int id, QIODevice::OpenMode mode, VfsFlags flags, const QString &contents, QString *errStr);
|
||||||
|
Reference in New Issue
Block a user