Commit e1541088 authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Destroy RecursiveImportCacheRepository after PersistentSymbolTableRepo

a8ffba2c cleared the persistent symbol
table caches in ~PersistentSymbolTable() to work around an
AddressSanitizer crash when a non-empty imports cache is destroyed after
the cache repository it references.

The constructor of the PersistentSymbolTable singleton creates a
PersistentSymbolTableRepo function-local static, then a
RecursiveImportCacheRepository function-local static. The order of
destruction of these 3 static objects is the reverse of the order of
their construction completion:
~PersistentSymbolTable()
recursiveImportCacheRepositoryObject's destruction
~PersistentSymbolTableRepo()

Since PersistentSymbolTableRepo::importsCache depends on
recursiveImportCacheRepositoryObject and not vice versa, a proper fix is
to create the cache repository before and thus destroy after the
persistent symbol table repository.
parent 17d3a563
......@@ -227,15 +227,13 @@ void PersistentSymbolTable::clearCache()
PersistentSymbolTable::PersistentSymbolTable()
{
ItemRepositoryFor<PersistentSymbolTable>::init();
// PersistentSymbolTableRepo::importsCache uses RecursiveImportCacheRepository, so the cache repository must be
// destroyed after and therefore created before the persistent symbol table repository.
RecursiveImportCacheRepository::repository();
ItemRepositoryFor<PersistentSymbolTable>::init();
}
PersistentSymbolTable::~PersistentSymbolTable()
{
// clear cache early to ensure we don't keep items referenced from other repositories
clearCache();
}
PersistentSymbolTable::~PersistentSymbolTable() = default;
void PersistentSymbolTable::addDeclaration(const IndexedQualifiedIdentifier& id, const IndexedDeclaration& declaration)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment