Affected code File: include/lua/sol/usertype_storage.hpp Function: usertype_storage_base::self_index_call(...)
Snippet: stateless_reference* target = nullptr; { stack_reference k = stack::get<stack_reference>(L, 2); auto it = self.auxiliary_keys.find(k); if (it != self.auxiliary_keys.cend()) { target = &it->second; } }
Problem auxiliary_keys is std::unordered_map<stateless_reference, ...>. Calling find(k) with k of type stack_reference can implicitly create a temporary stateless_reference via stateless_reference(lua_State*, const stack_reference&), which allocates a new Lua registry reference. Because stateless_reference cannot free in its destructor (no lua_State*), this temporary’s registry ref is never released, causing a leak on each lookup when heterogeneous lookup is not active.
Impact Repeated non-string key lookups (e.g., table/lightuserdata keys) cause unbounded growth of Lua registry entries and memory usage.