From 7fdc8fdbfe0d2b4bc0f1a22b2560ca6d86a72c94 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 16 Nov 2012 03:34:57 +0000 Subject: [PATCH] [libclang] When caching code-completion results, pass the CachedCompletionAllocator to the CodeCompletionTUInfo that is going to be used to get the results. Previously we would use ASTUnit's CodeCompletionTUInfo which has its own allocator that will go away when we reparse. That could result in a use-after-free bug when getting the parent context name from a CodeCompletionString. Addresses rdar://12568377. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168133 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/ASTUnit.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 553fb21a68..d00b7659d2 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -356,8 +356,9 @@ void ASTUnit::CacheCodeCompletionResults() { typedef CodeCompletionResult Result; SmallVector Results; CachedCompletionAllocator = new GlobalCodeCompletionAllocator; + CodeCompletionTUInfo CCTUInfo(CachedCompletionAllocator); TheSema->GatherGlobalCodeCompletions(*CachedCompletionAllocator, - getCodeCompletionTUInfo(), Results); + CCTUInfo, Results); // Translate global code completions into cached completions. llvm::DenseMap CompletionTypes; @@ -369,7 +370,7 @@ void ASTUnit::CacheCodeCompletionResults() { CachedCodeCompletionResult CachedResult; CachedResult.Completion = Results[I].CreateCodeCompletionString(*TheSema, *CachedCompletionAllocator, - getCodeCompletionTUInfo(), + CCTUInfo, IncludeBriefCommentsInCodeCompletion); CachedResult.ShowInContexts = getDeclShowContexts(Results[I].Declaration, Ctx->getLangOpts(), @@ -435,7 +436,7 @@ void ASTUnit::CacheCodeCompletionResults() { CachedResult.Completion = Results[I].CreateCodeCompletionString(*TheSema, *CachedCompletionAllocator, - getCodeCompletionTUInfo(), + CCTUInfo, IncludeBriefCommentsInCodeCompletion); CachedResult.ShowInContexts = RemainingContexts; CachedResult.Priority = CCP_NestedNameSpecifier; @@ -458,7 +459,7 @@ void ASTUnit::CacheCodeCompletionResults() { CachedResult.Completion = Results[I].CreateCodeCompletionString(*TheSema, *CachedCompletionAllocator, - getCodeCompletionTUInfo(), + CCTUInfo, IncludeBriefCommentsInCodeCompletion); CachedResult.ShowInContexts = (1LL << CodeCompletionContext::CCC_TopLevel) -- 2.40.0