[LLVMdev] How to avoid memory leaks

Jeffrey Yasskin jyasskin at google.com
Tue Mar 23 13:59:04 PDT 2010


Are you calling llvm_shutdown() at the end of your program? You
should. valgrind reports "possible" leaks when it finds a pointer
pointing inside a memory block (as opposed to at the first byte), and
LLVM uses those a lot. llvm_shutdown() will free a lot of that memory,
including the LLVMContext, which should remove any false leaks you
might be seeing.

On the other hand, the TypePrinting() leak looks like it should keep a
pointer to the beginning of the block it allocates, and like it should
delete that object on destruction, so something weird is going on. One
weird thing might be if you built LLVM in -Asserts mode but didn't
define NDEBUG in your own build, since that'll break the LLVM ABI in
odd ways.

I note that your LLVM has no debug symbols, which may imply that you
built it in Release mode (which is independent of +/- Asserts). It'll
be easier to track things down if you build LLVM in Debug mode.

Can you reproduce any of the leaks with a very short program? If you
can, send the whole short program and the exact command line you used
to build it, along with the output of `llvm-config --build-mode`. (We
need to reproduce your problem locally in order to fix it.) Note that
if the leaks appear on
http://google1.osuosl.org:8011/builders/llvm-x86_64-linux-vg_leak/builds/5/steps/test-llvm/logs/stdio
we already know about them and are working on fixes.

On Tue, Mar 23, 2010 at 12:42 PM, Gabi <bugspynet at gmail.com> wrote:
> Hi Jeffrey,
> Listed below the Full valgrind report (using latest revision r99309)
> The program creates many thousands of instructions and values as you
> can see from the report below
>
> ...



More information about the llvm-dev mailing list