mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
job: Fix job_wait to properly cleanup the job when it exits.
This commit is contained in:
parent
d5d98f14b6
commit
d878569dc7
@ -327,6 +327,9 @@ void job_stop(Job *job)
|
|||||||
/// is possible on some OS.
|
/// is possible on some OS.
|
||||||
int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
|
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
|
// Increase refcount to stop the job from being freed before we have a
|
||||||
// chance to get the status.
|
// chance to get the status.
|
||||||
job->refcount++;
|
job->refcount++;
|
||||||
@ -342,15 +345,16 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
|
|||||||
event_poll(0);
|
event_poll(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!--job->refcount) {
|
if (job->refcount == 1) {
|
||||||
int status = (int) job->status;
|
// Job exited, collect status and manually invoke close_cb to free the job
|
||||||
// Manually invoke close_cb to free the job resources
|
// resources
|
||||||
|
status = job->status;
|
||||||
close_cb((uv_handle_t *)&job->proc);
|
close_cb((uv_handle_t *)&job->proc);
|
||||||
return status;
|
} else {
|
||||||
|
job->refcount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return -1 for a timeout
|
return status;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the pipe used to write to the job.
|
/// Close the pipe used to write to the job.
|
||||||
|
Loading…
Reference in New Issue
Block a user