clang::CompilerInstance leaks memory on compilation failures


I am using the clang::CompilerInstance to compile a piece of code. I am running my tests through Clang -fsanitize=address.
The test case where the compilation succeeds does not leak any memory. But if the compilation fails, then it seems to leak memory.

Is this a known bug?

Am I supposed to explicitly freeup somethings when the compilation fails (The code already calls llvm::shut_down() towards the end of the process)

if(!clang.ExecuteAction(*action)) { throw new CompilationError(“failed to compile”, std::move(errors)); }

The rest of the code looks similar to what others have posted on the internet (but haven’t gotten a response yet):

I am using Clang3.5