Potential memory leak for the TF_REGISTRY_FUNCTION macro
Author: plattfotCreated Sep 14, 2026Updated Sep 15, 2026
Hi,
I'm getting a memory leak report from the LSan in gcc when building an usd plugin. I've traced it down to be something with the registry TF_REGISTRY_FUNCTION macro, more specific the Tf_RegistryInit::Add(…) function call in that macro.
=================================================================
==1438301==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1544 byte(s) in 1 object(s) allocated from:
#0 0x7fc482eb6367 in operator new(unsigned long) (/lib64/libasan.so.6+0xb6367)
#1 0x7fc481fe5af6 in std::vector<__gnu_cxx::_Hashtable_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::list<pxrInternal_v0_26_5__pxrReserved__::(anonymous namespace)::Tf_RegistryManagerImpl::_RegistryValue, std::allocator<pxrInternal_v0_26_5__pxrReserved__::(anonymous namespace)::Tf_RegistryManagerImpl::_RegistryValue> > > >*, std::allocator<__gnu_cxx::_Hashtable_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::list<pxrInternal_v0_26_5__pxrReserved__::(anonymous namespace)::Tf_RegistryManagerImpl::_RegistryValue, std::allocator<pxrInternal_v0_26_5__pxrReserved__::(anonymous namespace)::Tf_RegistryManagerImpl::_RegistryValue> > > >*> >::reserve(unsigned long) [clone .constprop.0] (/path/to/usd/lib/libusd_tf.so+0xeaaf6)
Direct leak of 31 byte(s) in 1 object(s) allocated from:
#0 0x7fc482eb6367 in operator new(unsigned long) (/lib64/libasan.so.6+0xb6367)
#1 0x7fc48274adbd in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) (/lib64/libstdc++.so.6+0x14adbd)
SUMMARY: AddressSanitizer: 1575 byte(s) leaked in 2 allocation(s).I'm suspecting it is similar to #3088, although I'm seeing the extra leak from std::string::_M_mutate(…).
Steps to reproduce
I've stripped it down to this repro code:
usd_memory_leak_repro.cpp:
int repro_call();
int main() { return repro_call(); }lib.cpp:
#include <pxr/usd/usd/schemaRegistry.h>
PXR_NAMESPACE_OPEN_SCOPE
TF_REGISTRY_FUNCTION(TfType)
{
}
PXR_NAMESPACE_CLOSE_SCOPE
// Have something to force the linker to link this library.
int repro_call()
{
return 0;
}CMakeLists.txt:
cmake_minimum_required(VERSION 3.30)
project(UsdMemoryLeakRepro VERSION 0.1 LANGUAGES CXX)
find_package(pxr CONFIG COMPONENTS usd)
add_library(repro SHARED)
target_sources(repro PRIVATE lib.cpp)
target_link_libraries(repro PRIVATE usd -fsanitize=address)
add_executable(usd_memory_leak_repro)
target_sources(usd_memory_leak_repro PRIVATE usd_memory_leak_repro.cpp)
target_link_libraries(usd_memory_leak_repro PUBLIC repro -fsanitize=address)Simply build and run the executable and you should see a similar output as above
Version
usd: 26.05 compiler: gcc-11.4.0 OS: Rocky Linux 9
Source: PixarAnimationStudios/OpenUSD