executor: Fix some memory leaks

This commit is contained in:
ZyX
2017-01-29 19:32:01 +03:00
parent e1bbaca7ac
commit 295e7607c4
3 changed files with 21 additions and 1 deletions

View File

@@ -182,8 +182,14 @@ static int nlua_exec_luado_string(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL
if (luaL_loadbuffer(lstate, lcmd, lcmd_len, NLUA_EVAL_NAME)) { if (luaL_loadbuffer(lstate, lcmd, lcmd_len, NLUA_EVAL_NAME)) {
nlua_error(lstate, _("E5109: Error while creating lua chunk: %.*s")); nlua_error(lstate, _("E5109: Error while creating lua chunk: %.*s"));
if (lcmd_len >= IOSIZE) {
xfree(lcmd);
}
return 0; return 0;
} }
if (lcmd_len >= IOSIZE) {
xfree(lcmd);
}
if (lua_pcall(lstate, 0, 1, 0)) { if (lua_pcall(lstate, 0, 1, 0)) {
nlua_error(lstate, _("E5110: Error while creating lua function: %.*s")); nlua_error(lstate, _("E5110: Error while creating lua function: %.*s"));
return 0; return 0;

View File

@@ -62,6 +62,15 @@ describe(':lua command', function()
eq(NIL, funcs.luaeval('lvar')) eq(NIL, funcs.luaeval('lvar'))
eq(42, funcs.luaeval('gvar')) eq(42, funcs.luaeval('gvar'))
end) end)
it('works with long strings', function()
local s = ('x'):rep(100500)
eq('\nE5104: Error while creating lua chunk: [string "<VimL compiled string>"]:1: unfinished string near \'<eof>\'', redir_exec(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s})'):format(s)))
eq({''}, curbufmeths.get_lines(0, -1, false))
eq('', redir_exec(('lua vim.api.nvim_buf_set_lines(1, 1, 2, false, {"%s"})'):format(s)))
eq({'', s}, curbufmeths.get_lines(0, -1, false))
end)
end) end)
describe(':luado command', function() describe(':luado command', function()
@@ -104,6 +113,10 @@ describe(':luado command', function()
end) end)
it('works with long strings', function() it('works with long strings', function()
local s = ('x'):rep(100500) local s = ('x'):rep(100500)
eq('\nE5109: Error while creating lua chunk: [string "<VimL compiled string>"]:1: unfinished string near \'<eof>\'', redir_exec(('luado return "%s'):format(s)))
eq({''}, curbufmeths.get_lines(0, -1, false))
eq('', redir_exec(('luado return "%s"'):format(s))) eq('', redir_exec(('luado return "%s"'):format(s)))
eq({s}, curbufmeths.get_lines(0, -1, false)) eq({s}, curbufmeths.get_lines(0, -1, false))
end) end)

View File

@@ -243,10 +243,11 @@ describe('luaeval()', function()
exc_exec([[call luaeval("error('ERROR')")]])) exc_exec([[call luaeval("error('ERROR')")]]))
end) end)
it('does not leak memory when called with too long line with syntax error', it('does not leak memory when called with too long line',
function() function()
local s = ('x'):rep(65536) local s = ('x'):rep(65536)
eq('Vim(call):E5107: Error while creating lua chunk for luaeval(): [string "<VimL compiled string>"]:1: unexpected symbol near \')\'', eq('Vim(call):E5107: Error while creating lua chunk for luaeval(): [string "<VimL compiled string>"]:1: unexpected symbol near \')\'',
exc_exec([[call luaeval("(']] .. s ..[[' + )")]])) exc_exec([[call luaeval("(']] .. s ..[[' + )")]]))
eq(s, funcs.luaeval('"' .. s .. '"'))
end) end)
end) end)