job: Only decrease refcount after settmode in job_wait

This is required to prevent the scenario explained by @akkartik in #1324
This commit is contained in:
Thiago de Arruda
2014-10-23 17:00:46 -03:00
parent 6f5f3faa84
commit f05fead12e

View File

@@ -291,7 +291,6 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
// Until... // Until...
got_int || // interrupted by the user got_int || // interrupted by the user
job->refcount == 1); // job exited job->refcount == 1); // job exited
job->refcount--;
// we'll assume that a user frantically hitting interrupt doesn't like // we'll assume that a user frantically hitting interrupt doesn't like
// the current job. Signal that it has to be killed. // the current job. Signal that it has to be killed.
@@ -302,7 +301,7 @@ int job_wait(Job *job, int ms) FUNC_ATTR_NONNULL_ALL
settmode(old_mode); settmode(old_mode);
if (!job->refcount) { if (!--job->refcount) {
int status = (int) job->status; int status = (int) job->status;
// Manually invoke close_cb to free the job resources // Manually invoke close_cb to free the job resources
close_cb((uv_handle_t *)&job->proc); close_cb((uv_handle_t *)&job->proc);