From 3b89fee24632cfddbff5714a509c1c3b72a235c5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 11 Nov 2021 09:34:23 +0800 Subject: fix(channel): throw error if sending to internal channel w/o terminal Prevent SIGABRT when sending to a channel created by nvim_open_term() after the associated terminal has been deleted. --- src/nvim/channel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/channel.c b/src/nvim/channel.c index 0eae87c1f8..9662f6205f 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -535,7 +535,11 @@ size_t channel_send(uint64_t id, char *data, size_t len, bool data_owned, const goto retfree; } - if (chan->streamtype == kChannelStreamInternal && chan->term) { + if (chan->streamtype == kChannelStreamInternal) { + if (!chan->term) { + *error = _("Can't send data to closed stream"); + goto retfree; + } terminal_receive(chan->term, data, len); written = len; goto retfree; -- cgit From a502a7a7311657564065c9d2cd1a64292550722c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 11 Nov 2021 09:34:23 +0800 Subject: fix(channel): fix channels opened by nvim_open_term() never being freed --- src/nvim/api/vim.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') 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); } -- cgit