aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/vim.c3
-rw-r--r--test/functional/core/channels_spec.lua18
2 files changed, 13 insertions, 8 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 2fbafb9889..c1374ff00e 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -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);
}
diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua
index e5ded6428f..f93ab0885f 100644
--- a/test/functional/core/channels_spec.lua
+++ b/test/functional/core/channels_spec.lua
@@ -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)