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