diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-31 10:19:24 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-10-31 22:52:10 -0300 |
commit | d878569dc78c9beb5052809d21bb0ffba76e7809 (patch) | |
tree | ecaf7bcc167ac380d0261e0acb5e1ac34c4ca301 | |
parent | d5d98f14b68503bc9ad85c706ba0e52fb054ecbb (diff) | |
download | rneovim-d878569dc78c9beb5052809d21bb0ffba76e7809.tar.gz rneovim-d878569dc78c9beb5052809d21bb0ffba76e7809.tar.bz2 rneovim-d878569dc78c9beb5052809d21bb0ffba76e7809.zip |
job: Fix job_wait to properly cleanup the job when it exits.
-rw-r--r-- | src/nvim/os/job.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/nvim/os/job.c b/src/nvim/os/job.c index 4abc336e67..8c744b0479 100644 --- a/src/nvim/os/job.c +++ b/src/nvim/os/job.c @@ -327,6 +327,9 @@ void job_stop(Job *job) /// is possible on some OS. int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL { + // The default status is -1, which represents a timeout + int status = -1; + // Increase refcount to stop the job from being freed before we have a // chance to get the status. job->refcount++; @@ -342,15 +345,16 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL event_poll(0); } - if (!--job->refcount) { - int status = (int) job->status; - // Manually invoke close_cb to free the job resources + if (job->refcount == 1) { + // Job exited, collect status and manually invoke close_cb to free the job + // resources + status = job->status; close_cb((uv_handle_t *)&job->proc); - return status; + } else { + job->refcount--; } - // return -1 for a timeout - return -1; + return status; } /// Close the pipe used to write to the job. |