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.
This commit is contained in:
zeertzjq 2021-11-11 09:34:23 +08:00
parent 14def4d227
commit 3b89fee246
2 changed files with 15 additions and 1 deletions

View File

@ -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;

View File

@ -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)