lua: fix tuple leak in <key_def>.compare_with_key
The key difference between lbox_encode_tuple_on_gc() and luaT_tuple_encode() is that the latter never raises a Lua error, but passes an error using the diagnostics area. Aside of the tuple leak, the patch fixes fiber region's memory 'leak' (till fiber_gc()). Before the patch, the memory that is used for serialization of the key is not freed (region_truncate()) when the serialization fails. It is verified in the gh-5388-<...> test. While I'm here, added a test case that just verifies correct behaviour in case of a key serialization failure (added into key_def.test.lua). The case does not verify whether a tuple leaks and it is successful as before this patch as well after the patch. I don't find a simple way to check the tuple leak within a test. Verified manually using the reproducer from the linked issue. Fixes #5388
Showing
- changelogs/unreleased/fix-tuple-leak-in-lua-key_def.md 4 additions, 0 deletionschangelogs/unreleased/fix-tuple-leak-in-lua-key_def.md
- src/box/lua/key_def.c 2 additions, 3 deletionssrc/box/lua/key_def.c
- test/box-tap/gh-5388-lua-key_def-leak.test.lua 82 additions, 0 deletionstest/box-tap/gh-5388-lua-key_def-leak.test.lua
- test/box-tap/key_def.test.lua 7 additions, 1 deletiontest/box-tap/key_def.test.lua
Please register or sign in to comment