[LLVMdev] How to avoid memory leaks

Reid Kleckner rnk at mit.edu
Tue Mar 23 07:49:00 PDT 2010


On Tue, Mar 23, 2010 at 7:04 AM, Gabi <bugspynet at gmail.com> wrote:
> Hi
> I get huge memory leaks using LLVM IRBuilder (trunk version)
>
> Basically I recreate a function over and over again, and pretty sure
> that my code doesn't cause the leak
> while(true)
> {
>  Function *fn = module->getFunction(name);
>    if (fn)
>       fn->eraseFromParent();

Err, shouldn't you delete fn here?  I'm pretty sure that this just
removes the function from the module.

>    fn =  cast<Function>(module->getOrInsertFunction(name, fnType));
>    fillFunction(fn); //Fill function with some blocks and instructions..
> }

Reid




More information about the llvm-dev mailing list