aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/FrontendAction.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-05-04 14:59:20 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2015-05-04 14:59:20 +0000
commit4a8212a48887f16427accbeb2b231057f2c32ecf (patch)
treed5fa2a32f76421ea50a6686c3f3f04fe0d8769d9 /clang/lib/Frontend/FrontendAction.cpp
parentc312ef1d173bdf261479c9207f495dc25c3358f2 (diff)
downloadllvm-4a8212a48887f16427accbeb2b231057f2c32ecf.zip
llvm-4a8212a48887f16427accbeb2b231057f2c32ecf.tar.gz
llvm-4a8212a48887f16427accbeb2b231057f2c32ecf.tar.bz2
Reapply "Frontend: Stop leaking when not -disable-free"
This reverts commit r236422, effectively reapplying r236419. ASan helped me diagnose the problem: the non-leaking logic would free the ASTConsumer before freeing Sema whenever `isCurrentASTFile()`, causing a use-after-free in `Sema::~Sema()`. This version unconditionally frees Sema and the ASTContext before freeing the ASTConsumer. Without the fix, these were either being freed before the ASTConsumer was freed or leaked after, but they were always spiritually released so this isn't really a functionality change. I ran all of check-clang with ASan locally this time, so I'm hoping there aren't any more problems lurking. Original commit message: Try again to plug a leak that's been around since at least r128011 after coming across the FIXME. Nico Weber tried something similar in r207065 but had to revert in r207070 due to a bot failure. The build failure isn't visible anymore so I'm not sure what went wrong. I'm doing this slightly differently -- when not -disable-free I'm still resetting the members (just not leaking them) -- so maybe it will work out this time? Tests pass locally, anyway. llvm-svn: 236424
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r--clang/lib/Frontend/FrontendAction.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index d42ca71..9bba755 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -468,16 +468,12 @@ void FrontendAction::EndSourceFile() {
// FIXME: There is more per-file stuff we could just drop here?
bool DisableFree = CI.getFrontendOpts().DisableFree;
if (DisableFree) {
- if (!isCurrentFileAST()) {
- CI.resetAndLeakSema();
- CI.resetAndLeakASTContext();
- }
+ CI.resetAndLeakSema();
+ CI.resetAndLeakASTContext();
BuryPointer(CI.takeASTConsumer().get());
} else {
- if (!isCurrentFileAST()) {
- CI.setSema(nullptr);
- CI.setASTContext(nullptr);
- }
+ CI.setSema(nullptr);
+ CI.setASTContext(nullptr);
CI.setASTConsumer(nullptr);
}
@@ -494,13 +490,16 @@ void FrontendAction::EndSourceFile() {
// FrontendAction.
CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles());
- // FIXME: Only do this if DisableFree is set.
if (isCurrentFileAST()) {
- CI.resetAndLeakSema();
- CI.resetAndLeakASTContext();
- CI.resetAndLeakPreprocessor();
- CI.resetAndLeakSourceManager();
- CI.resetAndLeakFileManager();
+ if (DisableFree) {
+ CI.resetAndLeakPreprocessor();
+ CI.resetAndLeakSourceManager();
+ CI.resetAndLeakFileManager();
+ } else {
+ CI.setPreprocessor(nullptr);
+ CI.setSourceManager(nullptr);
+ CI.setFileManager(nullptr);
+ }
}
setCompilerInstance(nullptr);