From 5c22f07c4f2b8ae9f7d756373ae8541051d7bd81 Mon Sep 17 00:00:00 2001 From: oni-link Date: Sun, 11 Jan 2015 22:06:23 +0100 Subject: job.c: Prevent early return from job_wait(). A blocking call job_wait(job, -1) can only return after job is finished and all handles of job are closed. But hitting CTRL-C makes job_wait() return early while handles can still be open. This can lead to problems with the job/handle callbacks if the caller (of job_wait()) already freed the memory that is used in the job callbacks. To fix this, only return after all handles of the job are closed. --- src/nvim/os/job.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index 17872ab9c9..8db5e3cc39 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -310,8 +310,15 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL // we'll assume that a user frantically hitting interrupt doesn't like // the current job. Signal that it has to be killed. if (got_int) { + got_int = false; job_stop(job); - event_poll(0); + if (ms == -1) { + // We can only return, if all streams/handles are closed and the job + // exited. + event_poll_until(-1, job->refcount == 1); + } else { + event_poll(0); + } } if (job->refcount == 1) { -- cgit