mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
fix(lua): memory leak when using invalid syntax with exists() (#26530)
This commit is contained in:
parent
1d4a5cd185
commit
b40170f7a3
@ -2323,10 +2323,12 @@ bool nlua_func_exists(const char *lua_funcname)
|
||||
vim_snprintf(str, length, "return %s", lua_funcname);
|
||||
ADD_C(args, CSTR_AS_OBJ(str));
|
||||
Error err = ERROR_INIT;
|
||||
Object result = NLUA_EXEC_STATIC("return type(loadstring(...)()) =='function'", args, &err);
|
||||
Object result = NLUA_EXEC_STATIC("return type(loadstring(...)()) == 'function'", args, &err);
|
||||
xfree(str);
|
||||
|
||||
api_clear_error(&err);
|
||||
if (result.type != kObjectTypeBoolean) {
|
||||
api_free_object(result);
|
||||
return false;
|
||||
}
|
||||
return result.data.boolean;
|
||||
|
@ -3351,32 +3351,23 @@ describe('vim.keymap', function()
|
||||
|
||||
eq(1, exec_lua[[return GlobalCount]])
|
||||
end)
|
||||
|
||||
it('exists() can check a lua function', function()
|
||||
eq(true, exec_lua[[
|
||||
_G.test = function() print("hello") end
|
||||
return vim.fn.exists('v:lua.test') == 1
|
||||
]])
|
||||
|
||||
eq(true, exec_lua[[
|
||||
return vim.fn.exists('v:lua.require("mpack").decode') == 1
|
||||
]])
|
||||
|
||||
eq(true, exec_lua[[
|
||||
return vim.fn.exists("v:lua.require('vim.lsp').start") == 1
|
||||
]])
|
||||
|
||||
eq(true, exec_lua[[
|
||||
return vim.fn.exists('v:lua.require"vim.lsp".start') == 1
|
||||
]])
|
||||
|
||||
eq(true, exec_lua[[
|
||||
return vim.fn.exists("v:lua.require'vim.lsp'.start") == 1
|
||||
]])
|
||||
|
||||
eq(false, exec_lua[[
|
||||
return vim.fn.exists("v:lua.require'vim.lsp'.unknown") == 1
|
||||
]])
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe('Vimscript function exists()', function()
|
||||
it('can check a lua function', function()
|
||||
eq(1, exec_lua[[
|
||||
_G.test = function() print("hello") end
|
||||
return vim.fn.exists('v:lua.test')
|
||||
]])
|
||||
|
||||
eq(1, funcs.exists('v:lua.require("mpack").decode'))
|
||||
eq(1, funcs.exists("v:lua.require('mpack').decode"))
|
||||
eq(1, funcs.exists('v:lua.require"mpack".decode'))
|
||||
eq(1, funcs.exists("v:lua.require'mpack'.decode"))
|
||||
eq(1, funcs.exists("v:lua.require('vim.lsp').start"))
|
||||
eq(1, funcs.exists('v:lua.require"vim.lsp".start'))
|
||||
eq(1, funcs.exists("v:lua.require'vim.lsp'.start"))
|
||||
eq(0, funcs.exists("v:lua.require'vim.lsp'.unknown"))
|
||||
eq(0, funcs.exists('v:lua.?'))
|
||||
end)
|
||||
end)
|
||||
|
@ -639,9 +639,7 @@ t2]])
|
||||
{1:│}t1 |
|
||||
{1:│}^ |
|
||||
{1:+}{2:+-- 2 lines: # h2·····················}|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|*3
|
||||
{4:-- INSERT --} |
|
||||
]]}
|
||||
|
||||
@ -656,10 +654,7 @@ t2]])
|
||||
{1:-}^t1 |
|
||||
{1:-}# h2 |
|
||||
{1:│}t2 |
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|
|
||||
{3:~ }|*4
|
||||
1 line less; before #2 {MATCH:.*}|
|
||||
]]}
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user