Memory leaks in LLVM on linux

I am trying to figure out how to free up some memory that seems to be lost when running valgrind under our internal application. The stack traces I get are:

==19966== 4 bytes in 1 blocks are still reachable in loss record 1 of 12

==19966== at 0x402569A: operator new(unsigned int) (vg_replace_malloc.c:255)

==19966== by 0x5D9BBE8: void* llvm::object_creatorllvm::PassRegistry()

(ManagedStatic.h:25)

==19966== by 0x5E05AB6: llvm::ManagedStaticBase::RegisterManagedStatic(void*

()(), void ()(void*)) const (ManagedStatic.cpp:47)

==19966== by 0x5D9B73E: llvm::ManagedStaticllvm::PassRegistry::operator*()

(ManagedStatic.h:67)

==19966== by 0x5D997E1: llvm::PassRegistry::getPassRegistry()

(PassRegistry.cpp:34)

==19966== by 0x5D86960:

llvm::PassRegistrationListener::~PassRegistrationListener() (Pass.cpp:227)

==19966== by 0x5D86A39: llvm::PassNameParser::~PassNameParser()

(Pass.cpp:237)

==19966== by 0x5D948A5: llvm::cl::list<llvm::PassInfo const*, bool,

llvm::PassNameParser>::~list() (CommandLine.h:1010)

==19966== by 0x5D88E61: __tcf_2 (PassManager.cpp:69)

==19966== by 0x660A587: __cxa_finalize (cxa_finalize.c:56)

==19966== by 0x4A8D842: ??? (in

/home/mvillmow/Source/stg/opencl/drivers/opencl/dist/linux/debug/lib/x86/libamdoclcl32.so)

==19966== by 0x5E2F85B: ??? (in

/home/mvillmow/Source/stg/opencl/drivers/opencl/dist/linux/debug/lib/x86/libamdoclcl32.so)

==19966==

==19966== 12 bytes in 1 blocks are still reachable in loss record 2 of 12

==19966== at 0x402569A: operator new(unsigned int) (vg_replace_malloc.c:255)

==19966== by 0x5660DA0: void*

llvm::object_creator<llvm::sys::SmartMutex >() (ManagedStatic.h:25)

==19966== by 0x5E05AB6: llvm::ManagedStaticBase::RegisterManagedStatic(void*

()(), void ()(void*)) const (ManagedStatic.cpp:47)

==19966== by 0x566056A: llvm::ManagedStatic<llvm::sys::SmartMutex

::operator*() (ManagedStatic.h:67)

==19966== by 0x5D9984C:

llvm::PassRegistry::removeRegistrationListener(llvm::PassRegistrationListener*)

(PassRegistry.cpp:194)

==19966== by 0x5D86971:

llvm::PassRegistrationListener::~PassRegistrationListener() (Pass.cpp:227)

==19966== by 0x5D86A39: llvm::PassNameParser::~PassNameParser()

(Pass.cpp:237)

==19966== by 0x5D948A5: llvm::cl::list<llvm::PassInfo const*, bool,

llvm::PassNameParser>::~list() (CommandLine.h:1010)

==19966== by 0x5D88E61: __tcf_2 (PassManager.cpp:69)

==19966== by 0x660A587: __cxa_finalize (cxa_finalize.c:56)

==19966== by 0x4A8D842: ??? (in

/home/mvillmow/Source/stg/opencl/drivers/opencl/dist/linux/debug/lib/x86/libamdoclcl32.so)

==19966== by 0x5E2F85B: ??? (in

/home/mvillmow/Source/stg/opencl/drivers/opencl/dist/linux/debug/lib/x86/libamdoclcl32.so)

==19966==

==19966== 24 bytes in 1 blocks are still reachable in loss record 3 of 12

==19966== at 0x4024F20: malloc (vg_replace_malloc.c:236)

==19966== by 0x5E0741A: llvm::sys::MutexImpl::MutexImpl(bool) (Mutex.cpp:65)

==19966== by 0x5660D66: llvm::sys::SmartMutex::SmartMutex(bool)

(Mutex.h:93)

==19966== by 0x5660DB2: void*

llvm::object_creator<llvm::sys::SmartMutex >() (ManagedStatic.h:25)

==19966== by 0x5E05AB6: llvm::ManagedStaticBase::RegisterManagedStatic(void*

()(), void ()(void*)) const (ManagedStatic.cpp:47)

==19966== by 0x566056A: llvm::ManagedStatic<llvm::sys::SmartMutex

::operator*() (ManagedStatic.h:67)

==19966== by 0x5D9984C:

llvm::PassRegistry::removeRegistrationListener(llvm::PassRegistrationListener*)

(PassRegistry.cpp:194)

==19966== by 0x5D86971:

llvm::PassRegistrationListener::~PassRegistrationListener() (Pass.cpp:227)

==19966== by 0x5D86A39: llvm::PassNameParser::~PassNameParser()

(Pass.cpp:237)

==19966== by 0x5D948A5: llvm::cl::list<llvm::PassInfo const*, bool,

llvm::PassNameParser>::~list() (CommandLine.h:1010)

==19966== by 0x5D88E61: __tcf_2 (PassManager.cpp:69)

==19966== by 0x660A587: __cxa_finalize (cxa_finalize.c:56)

Are these known issues? If so, how do I free this memory?

Thanks,

Micah

Hi Micah,

Please try calling llvm_shutdown()

-Chris

Chris,

I’m using a llvm_shutdown_obj object and it calls llvm_shutdown when I delete it. Do I need to call llvm_shutdown() again afterwards? It looks to me like the static object is being created after my program exits main().

Also, this can be easily reproduced with the following command:

valgrind --tool=memcheck --show-reachable=yes --leak-check=full --track-origins=yes --leak-check=full opt -disable-opt -O0

Micah

Ping! Anyone else have an idea on how to free memory in LLVM that is created after llvm_shutdown?

Micah

Hi Micah,

the --show-reachable=yes option of Valgrind is a bit too much for
practical use, see

These leaks are most certainly bound and can't cause major memory
problems during the program execution.

HTH,
Alex

Thanks!