aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/channel.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2022-06-18 18:53:12 +0200
committerGitHub <noreply@github.com>2022-06-18 09:53:12 -0700
commitff6b8f54359037790b300cb06a025f84f11d829a (patch)
tree5f12a1dbad771a375190ef78607a819dbc498f40 /src/nvim/channel.c
parent9c0f2253a5c014ba1ab7ee6e403a0b07c4e01b40 (diff)
downloadrneovim-ff6b8f54359037790b300cb06a025f84f11d829a.tar.gz
rneovim-ff6b8f54359037790b300cb06a025f84f11d829a.tar.bz2
rneovim-ff6b8f54359037790b300cb06a025f84f11d829a.zip
fix(terminal): coverity USE_AFTER_FREE #18978
Problem: Coverity reports use after free: *** CID 352784: Memory - illegal accesses (USE_AFTER_FREE) /src/nvim/buffer.c: 1508 in set_curbuf() 1502 if (old_tw != curbuf->b_p_tw) { 1503 check_colorcolumn(curwin); 1504 } 1505 } 1506 1507 if (bufref_valid(&prevbufref) && prevbuf->terminal != NULL) { >>> CID 352784: Memory - illegal accesses (USE_AFTER_FREE) >>> Calling "terminal_check_size" dereferences freed pointer "prevbuf->terminal". 1508 terminal_check_size(prevbuf->terminal); 1509 } 1510 } 1511 1512 /// Enter a new current buffer. 1513 /// Old curbuf must have been abandoned already! This also means "curbuf" may Solution: Change terminal_destroy and terminal_close to set caller storage to NULL, similar to XFREE_CLEAR. This aligns with the pattern found already in: terminal_destroy e897ccad3eb1e term_delayed_free 3e59c1e20d605
Diffstat (limited to 'src/nvim/channel.c')
-rw-r--r--src/nvim/channel.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index ecc3a24784..20fae3a206 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -142,7 +142,7 @@ bool channel_close(uint64_t id, ChannelPart part, const char **error)
api_free_luaref(chan->stream.internal.cb);
chan->stream.internal.cb = LUA_NOREF;
chan->stream.internal.closed = true;
- terminal_close(chan->term, 0);
+ terminal_close(&chan->term, 0);
} else {
channel_decref(chan);
}
@@ -705,7 +705,7 @@ static void channel_process_exit_cb(Process *proc, int status, void *data)
{
Channel *chan = data;
if (chan->term) {
- terminal_close(chan->term, status);
+ terminal_close(&chan->term, status);
}
// If process did not exit, we only closed the handle of a detached process.
@@ -798,8 +798,9 @@ static inline void term_delayed_free(void **argv)
return;
}
- terminal_destroy(chan->term);
- chan->term = NULL;
+ if (chan->term) {
+ terminal_destroy(&chan->term);
+ }
channel_decref(chan);
}