diff options
author | zeertzjq <zeertzjq@outlook.com> | 2021-11-11 09:34:23 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2021-11-11 09:34:23 +0800 |
commit | 3b89fee24632cfddbff5714a509c1c3b72a235c5 (patch) | |
tree | dfa063d5cfbc997deffe75118e4cd6ba322a6781 | |
parent | 14def4d2271a5bc5e6e6e774d291a9e0fd2477e0 (diff) | |
download | rneovim-3b89fee24632cfddbff5714a509c1c3b72a235c5.tar.gz rneovim-3b89fee24632cfddbff5714a509c1c3b72a235c5.tar.bz2 rneovim-3b89fee24632cfddbff5714a509c1c3b72a235c5.zip |
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.
-rw-r--r-- | src/nvim/channel.c | 6 | ||||
-rw-r--r-- | test/functional/core/channels_spec.lua | 10 |
2 files changed, 15 insertions, 1 deletions
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; diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 93dec9fb35..e5ded6428f 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -281,4 +281,14 @@ describe('channels', function() -- works correctly with no output eq({"notification", "exit", {id, 1, {''}}}, next_msg()) 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')) + end) end) |