Skip to content

Commit

Permalink
term_close: fix use-after-free
Browse files Browse the repository at this point in the history
Closes #4393
  • Loading branch information
oni-link authored and justinmk committed May 15, 2016
1 parent 8dd91dd commit f583bc9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/nvim/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -21701,15 +21701,26 @@ static void term_resize(uint16_t width, uint16_t height, void *d)
pty_process_resize(&data->proc.pty, width, height);
}

static inline void term_delayed_free(void **argv)
{
TerminalJobData *j = argv[0];
if (j->in.pending_reqs || j->out.pending_reqs || j->err.pending_reqs) {
queue_put(j->events, term_delayed_free, 1, j);
return;
}

terminal_destroy(j->term);
term_job_data_decref(j);
}

static void term_close(void *d)
{
TerminalJobData *data = d;
if (!data->exited) {
data->exited = true;
process_stop((Process *)&data->proc);
}
terminal_destroy(data->term);
term_job_data_decref(d);
queue_put(data->events, term_delayed_free, 1, data);
}

static void term_job_data_decref(TerminalJobData *data)
Expand Down

0 comments on commit f583bc9

Please sign in to comment.