]> granicus.if.org Git - clang/commitdiff
[libclang] Protect against a race condition where a thread
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 3 Jul 2012 16:30:52 +0000 (16:30 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 3 Jul 2012 16:30:52 +0000 (16:30 +0000)
may be destroying an ASTUnit while cleanupOnDiskMapAtExit is
getting called.

rdar://11781241

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159664 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/ASTUnit.cpp

index d2f63a80fee9c2ecefbaca909ab76439753ba396..7be25e96b4c3fbd73a393938d30ef90ed618b968 100644 (file)
@@ -116,7 +116,8 @@ static OnDiskDataMap &getOnDiskDataMap() {
 }
 
 static void cleanupOnDiskMapAtExit(void) {
-  // No mutex required here since we are leaving the program.
+  // Use the mutex because there can be an alive thread destroying an ASTUnit.
+  llvm::MutexGuard Guard(getOnDiskMutex());
   OnDiskDataMap &M = getOnDiskDataMap();
   for (OnDiskDataMap::iterator I = M.begin(), E = M.end(); I != E; ++I) {
     // We don't worry about freeing the memory associated with OnDiskDataMap.