[cfe-dev] Possible memory leak.

Andrey Tarasevich tarasevich.andrey at googlemail.com
Sun Jul 31 13:34:17 PDT 2011


Hello!

I think I might found a memory leak.

Assume following function and class ASTMutationAction

bool processFile(std::string inFile){
auto_ptr<CompilerInstance> compiler(new CompilerInstance);
compiler->createDiagnostics(0, NULL);
assert(compiler->hasDiagnostics());
const char *args[] =
{
  "-cc1",
  inFile.c_str()
};
std::cout << outFile << std::endl;
clang::CompilerInvocation::CreateFromArgs(
  compiler->getInvocation(),
  args,
  args + 2,
  compiler->getDiagnostics());
llvm::OwningPtr<clang::ASTFrontendAction> action(new ASTMutationAction());
compiler->ExecuteAction(*action);
}

class ASTMutationAction : public ASTFrontendAction {
protected:
virtual ASTConsumer* CreateASTConsumer(CompilerInstance& compiler,
       llvm::StringRef){
return new ASTConsumer();
}
};

In processFile(std::string) each time I pass path to a file. I'm getting
paths via directory traversal. So amount of executions of that function is
always somewhere between 1000 and 40000 times. Although ASTConsumer class is
not implemented the amount of memory used by the process is constantly
growing. As soon as line 'compiler->ExecuteAction(*action);' is commented
there is no memory leakage.

I though it was somewhere in my code, but even when I deleted all
implementation from ASTMutationAction class and left only stub, the memory
consumption continued to increase.

Is this a bug or I use clang somehow wrong?

best regards,
Andrey Tarasevich.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110731/ccb0502f/attachment.html>


More information about the cfe-dev mailing list