This is an archive of the discontinued LLVM Phabricator instance.

[clang-repl] Remove memory leak of ASTContext/TargetMachine.
ClosedPublic

Authored by sunho on Jun 16 2022, 10:53 AM.

Details

Summary

Removes memory leak of ASTContext and TargetMachine. When DisableFree is turned on, it intentionally leaks these instances as they can be trivially deallocated. This patch turns this off and delete Parser instance early so that they will not reference dangling pargma headers.

Asan shouldn't detect these as leaks normally, since burypointer is called for them. But, every invocation of incremental parser createa an additional leak of TargetMachine. If there are many invocations within a single test case, we easily reach number of leaks exceeding kGraveYardMaxSize (which is 12) and leaks start to get reported by asan buildbots.

Diff Detail

Event Timeline

sunho created this revision.Jun 16 2022, 10:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2022, 10:53 AM
sunho requested review of this revision.Jun 16 2022, 10:53 AM
This comment was removed by sunho.
sunho edited the summary of this revision. (Show Details)Jun 16 2022, 11:05 AM
sunho updated this revision to Diff 437632.Jun 16 2022, 11:33 AM

Remove leaks of targetmachine too.

sunho retitled this revision from [Interpreter][ClangRepl] Fix memory leak of ASTContext. to [Interpreter][ClangRepl] Remove memory leak of ASTContext/TargetMachine..Jun 16 2022, 11:35 AM
sunho edited the summary of this revision. (Show Details)
sunho edited the summary of this revision. (Show Details)
sunho added a subscriber: Purva-Chaudhari.EditedJun 16 2022, 11:59 AM

@Purva-Chaudhari Could you check this out? Basically, this should allow even long execute.cpp test case to be ran without asan failures.

sunho edited the summary of this revision. (Show Details)Jun 16 2022, 12:06 PM
sunho edited the summary of this revision. (Show Details)
sunho edited the summary of this revision. (Show Details)Jun 16 2022, 12:08 PM
sunho edited the summary of this revision. (Show Details)Jun 16 2022, 6:22 PM

@Purva-Chaudhari Could you check this out? Basically, this should allow even long execute.cpp test case to be ran without asan failures.

Sure

sunho retitled this revision from [Interpreter][ClangRepl] Remove memory leak of ASTContext/TargetMachine. to [clang-repl] Remove memory leak of ASTContext/TargetMachine..Jun 16 2022, 10:19 PM
Purva-Chaudhari added a comment.EditedJun 17 2022, 1:11 AM

Asan tests passing! Solves the memory leak issue for original as well as modified version of execute.cpp (Commit issue solved )

sunho added a comment.Jun 17 2022, 2:28 AM

Asan tests passing! Solves the memory leak issue for original as well as modified version of execute.cpp (Commit issue solved )

Nice!!

This revision is now accepted and ready to land.Jun 17 2022, 8:12 AM
This revision was landed with ongoing or failed builds.Jun 17 2022, 2:36 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2022, 2:36 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript