]> git.ipfire.org Git - thirdparty/rspamd.git/commit
Fix UCL object memory leak in Lua integration
authorVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 28 Oct 2025 10:54:39 +0000 (10:54 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Tue, 28 Oct 2025 10:54:39 +0000 (10:54 +0000)
commit2427e652810d45713bcccb3ac388fb710b4bdb2c
treee4bbf5ee6138a279fb9a539611f41e3210bbec2c
parentc0e3b41a7d328aff968678aa28f634e14e9e4657
Fix UCL object memory leak in Lua integration

When UCL objects are passed to Lua via ucl_object_push_lua_unwrapped(),
the reference count is incremented but the garbage collector finalizer
was not being called, causing memory leaks.

The issue is that Lua 5.1/LuaJIT does not support __gc metamethod for
tables, only for userdata. This fix adds proper garbage collection
support for both Lua versions:

- For Lua 5.1/LuaJIT: Add __gc metamethod to the userdata stored in
  the table at index [0], which properly triggers reference cleanup
- For Lua 5.2+: Use the existing table __gc metamethod which works
  correctly in newer Lua versions

This ensures that ucl_object_unref() is called exactly once when the
Lua wrapper is garbage collected, preventing memory leaks.
contrib/libucl/lua_ucl.c