mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 15:58:17 +00:00
fix(channel): fix channels opened by nvim_open_term() never being freed
This commit is contained in:
@@ -1006,7 +1006,6 @@ Integer nvim_open_term(Buffer buffer, DictionaryOf(LuaRef) opts, Error *err)
|
|||||||
Terminal *term = terminal_open(buf, topts);
|
Terminal *term = terminal_open(buf, topts);
|
||||||
terminal_check_size(term);
|
terminal_check_size(term);
|
||||||
chan->term = term;
|
chan->term = term;
|
||||||
channel_incref(chan);
|
|
||||||
return (Integer)chan->id;
|
return (Integer)chan->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1036,6 +1035,8 @@ static void term_close(void *data)
|
|||||||
Channel *chan = data;
|
Channel *chan = data;
|
||||||
terminal_destroy(chan->term);
|
terminal_destroy(chan->term);
|
||||||
chan->term = NULL;
|
chan->term = NULL;
|
||||||
|
api_free_luaref(chan->stream.internal.cb);
|
||||||
|
chan->stream.internal.cb = LUA_NOREF;
|
||||||
channel_decref(chan);
|
channel_decref(chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,6 +3,8 @@ local uname = helpers.uname
|
|||||||
local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq,
|
local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq,
|
||||||
helpers.eval, helpers.next_msg, helpers.ok, helpers.source
|
helpers.eval, helpers.next_msg, helpers.ok, helpers.source
|
||||||
local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths
|
local command, funcs, meths = helpers.command, helpers.funcs, helpers.meths
|
||||||
|
local exc_exec = helpers.exc_exec
|
||||||
|
local poke_eventloop = helpers.poke_eventloop
|
||||||
local sleep = helpers.sleep
|
local sleep = helpers.sleep
|
||||||
local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
|
local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv
|
||||||
local set_session = helpers.set_session
|
local set_session = helpers.set_session
|
||||||
@@ -283,12 +285,14 @@ describe('channels', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('should throw error when writing to a channel associated with a deleted terminal', function()
|
it('should throw error when writing to a channel associated with a deleted terminal', function()
|
||||||
source([[
|
command('let id = nvim_open_term(0, {})')
|
||||||
let id = nvim_open_term(0, {})
|
local err = exc_exec([[bdelete! | call chansend(id, 'test')]])
|
||||||
bdelete!
|
-- channel hasn't been freed yet
|
||||||
let v:errmsg = ''
|
eq("Vim(call):Can't send data to closed stream", err)
|
||||||
silent! call chansend(id, 'test')
|
-- process free_channel_event
|
||||||
]])
|
poke_eventloop()
|
||||||
eq("Can't send data to closed stream", eval('v:errmsg'))
|
err = exc_exec([[call chansend(id, 'test')]])
|
||||||
|
-- channel has ben freed
|
||||||
|
eq("Vim(call):E900: Invalid channel id", err)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user