mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -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);
|
vim_snprintf(str, length, "return %s", lua_funcname);
|
||||||
ADD_C(args, CSTR_AS_OBJ(str));
|
ADD_C(args, CSTR_AS_OBJ(str));
|
||||||
Error err = ERROR_INIT;
|
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);
|
xfree(str);
|
||||||
|
|
||||||
|
api_clear_error(&err);
|
||||||
if (result.type != kObjectTypeBoolean) {
|
if (result.type != kObjectTypeBoolean) {
|
||||||
|
api_free_object(result);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return result.data.boolean;
|
return result.data.boolean;
|
||||||
|
@ -3351,32 +3351,23 @@ describe('vim.keymap', function()
|
|||||||
|
|
||||||
eq(1, exec_lua[[return GlobalCount]])
|
eq(1, exec_lua[[return GlobalCount]])
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
it('exists() can check a lua function', function()
|
|
||||||
eq(true, exec_lua[[
|
describe('Vimscript function exists()', function()
|
||||||
_G.test = function() print("hello") end
|
it('can check a lua function', function()
|
||||||
return vim.fn.exists('v:lua.test') == 1
|
eq(1, exec_lua[[
|
||||||
]])
|
_G.test = function() print("hello") end
|
||||||
|
return vim.fn.exists('v:lua.test')
|
||||||
eq(true, exec_lua[[
|
]])
|
||||||
return vim.fn.exists('v:lua.require("mpack").decode') == 1
|
|
||||||
]])
|
eq(1, funcs.exists('v:lua.require("mpack").decode'))
|
||||||
|
eq(1, funcs.exists("v:lua.require('mpack').decode"))
|
||||||
eq(true, exec_lua[[
|
eq(1, funcs.exists('v:lua.require"mpack".decode'))
|
||||||
return vim.fn.exists("v:lua.require('vim.lsp').start") == 1
|
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(true, exec_lua[[
|
eq(1, funcs.exists("v:lua.require'vim.lsp'.start"))
|
||||||
return vim.fn.exists('v:lua.require"vim.lsp".start') == 1
|
eq(0, funcs.exists("v:lua.require'vim.lsp'.unknown"))
|
||||||
]])
|
eq(0, funcs.exists('v:lua.?'))
|
||||||
|
end)
|
||||||
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)
|
end)
|
||||||
|
@ -639,9 +639,7 @@ t2]])
|
|||||||
{1:│}t1 |
|
{1:│}t1 |
|
||||||
{1:│}^ |
|
{1:│}^ |
|
||||||
{1:+}{2:+-- 2 lines: # h2·····················}|
|
{1:+}{2:+-- 2 lines: # h2·····················}|
|
||||||
{3:~ }|
|
{3:~ }|*3
|
||||||
{3:~ }|
|
|
||||||
{3:~ }|
|
|
||||||
{4:-- INSERT --} |
|
{4:-- INSERT --} |
|
||||||
]]}
|
]]}
|
||||||
|
|
||||||
@ -656,10 +654,7 @@ t2]])
|
|||||||
{1:-}^t1 |
|
{1:-}^t1 |
|
||||||
{1:-}# h2 |
|
{1:-}# h2 |
|
||||||
{1:│}t2 |
|
{1:│}t2 |
|
||||||
{3:~ }|
|
{3:~ }|*4
|
||||||
{3:~ }|
|
|
||||||
{3:~ }|
|
|
||||||
{3:~ }|
|
|
||||||
1 line less; before #2 {MATCH:.*}|
|
1 line less; before #2 {MATCH:.*}|
|
||||||
]]}
|
]]}
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user