From 710002c820e5a55e3b234074fefb84ab745e11a3 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Wed, 25 Mar 2015 08:52:40 -0300 Subject: [PATCH] job: Close the process in a queued event handler Since all reads are queued by the event loop, we must also queue the exit event, or else the process_close function can close the job streams before received data is processed. --- src/nvim/os/job.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index 898d875ea3..ccd7891601 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -406,6 +406,12 @@ static void close_cb(uv_handle_t *handle) job_decref(handle_get_job(handle)); } +static void job_exited(Event event) +{ + Job *job = event.data; + process_close(job); +} + static void chld_handler(uv_signal_t *handle, int signum) { int stat = 0; @@ -433,7 +439,12 @@ static void chld_handler(uv_signal_t *handle, int signum) } else if (WIFSIGNALED(stat)) { job->status = WTERMSIG(stat); } - process_close(job); + if (exiting) { + // don't enqueue more events when exiting + process_close(job); + } else { + event_push((Event) {.handler = job_exited, .data = job}, false); + } break; } }