diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-08 09:18:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 09:18:03 +0800 |
commit | d0b3c872192152d5b09a92e53e3986b9fe64a3d9 (patch) | |
tree | 2fdff287ea8af9c62baea69c84dfd81fe88c4b4d | |
parent | dc2379b89bd00cf7aa661e1b000d2a419843df3f (diff) | |
download | rneovim-d0b3c872192152d5b09a92e53e3986b9fe64a3d9.tar.gz rneovim-d0b3c872192152d5b09a92e53e3986b9fe64a3d9.tar.bz2 rneovim-d0b3c872192152d5b09a92e53e3986b9fe64a3d9.zip |
fix(process): avoid potential data race on exit (#27769)
On exit, pty_process_close() may be called after pty_process_finish1()
but before start_wait_eof_timer(), in which case the timer shouldn't be
started because pty_process_close() has already closed it.
-rw-r--r-- | src/nvim/os/pty_process_win.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index cce27c31b4..12831ff05f 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -32,9 +32,10 @@ static void start_wait_eof_timer(void **argv) FUNC_ATTR_NONNULL_ALL { PtyProcess *ptyproc = (PtyProcess *)argv[0]; - Process *proc = (Process *)ptyproc; - uv_timer_start(&ptyproc->wait_eof_timer, wait_eof_timer_cb, 200, 200); + if (ptyproc->finish_wait != NULL) { + uv_timer_start(&ptyproc->wait_eof_timer, wait_eof_timer_cb, 200, 200); + } } /// @returns zero on success, or negative error code. @@ -214,6 +215,7 @@ static void wait_eof_timer_cb(uv_timer_t *wait_eof_timer) PtyProcess *ptyproc = wait_eof_timer->data; Process *proc = (Process *)ptyproc; + assert(ptyproc->finish_wait != NULL); if (proc->out.closed || proc->out.did_eof || !uv_is_readable(proc->out.uvstream)) { uv_timer_stop(&ptyproc->wait_eof_timer); pty_process_finish2(ptyproc); |