Skip to content

Commit 61a6605

Browse files
committed
patch 8.0.0746: when :term fails the job is not properly cleaned up
Problem: When :term fails the job is not properly cleaned up. Solution: Free the terminal. Handle a job that failed to start. (closes #1858)
1 parent 9f1f49b commit 61a6605

4 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/channel.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5189,6 +5189,11 @@ job_stop(job_T *job, typval_T *argvars, char *type)
51895189
return 0;
51905190
}
51915191
}
5192+
if (job->jv_status == JOB_FAILED)
5193+
{
5194+
ch_log(job->jv_channel, "Job failed to start, job_stop() skipped");
5195+
return 0;
5196+
}
51925197
if (job->jv_status == JOB_ENDED)
51935198
{
51945199
ch_log(job->jv_channel, "Job has already ended, job_stop() skipped");

src/os_unix.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5475,7 +5475,9 @@ mch_stop_job(job_T *job, char_u *how)
54755475
job_pid = -job_pid;
54765476
#endif
54775477

5478-
kill(job_pid, sig);
5478+
/* Never kill ourselves! */
5479+
if (job_pid != 0)
5480+
kill(job_pid, sig);
54795481

54805482
return OK;
54815483
}

src/terminal.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ ex_terminal(exarg_T *eap)
203203
}
204204
else
205205
{
206+
free_terminal(term);
207+
curbuf->b_term = NULL;
208+
206209
/* Wiping out the buffer will also close the window and call
207210
* free_terminal(). */
208211
do_buffer(DOBUF_WIPE, DOBUF_CURRENT, FORWARD, 0, TRUE);
@@ -235,7 +238,8 @@ free_terminal(term_T *term)
235238

236239
if (term->tl_job != NULL)
237240
{
238-
if (term->tl_job->jv_status != JOB_ENDED)
241+
if (term->tl_job->jv_status != JOB_ENDED
242+
&& term->tl_job->jv_status != JOB_FAILED)
239243
job_stop(term->tl_job, NULL, "kill");
240244
job_unref(term->tl_job);
241245
}
@@ -941,7 +945,9 @@ term_and_job_init(term_T *term, int rows, int cols, char_u *cmd)
941945
setup_job_options(&opt, rows, cols);
942946
term->tl_job = job_start(argvars, &opt);
943947

944-
return term->tl_job != NULL ? OK : FAIL;
948+
return term->tl_job != NULL
949+
&& term->tl_job->jv_channel != NULL
950+
&& term->tl_job->jv_status != JOB_FAILED ? OK : FAIL;
945951
}
946952

947953
/*

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
746,
772774
/**/
773775
745,
774776
/**/

0 commit comments

Comments
 (0)