Prevent crash when reaping jobs in exit handlers

If an interactive job is started, and it is reaped within fish's
exit handler, we may attempt to print its status message after
cur_term has been set to NULL. This results in a crash.

This change makes fish only print the status message if cur_term is
not NULL.

Fixes #3222
This commit is contained in:
ridiculousfish 2016-09-09 13:13:45 -07:00
parent f0125734d0
commit fa837a2e4a

View File

@ -514,7 +514,7 @@ void proc_fire_event(const wchar_t *msg, int type, pid_t pid, int status) {
event.arguments.resize(0);
}
int job_reap(bool interactive) {
int job_reap(bool allow_interactive) {
ASSERT_IS_MAIN_THREAD();
job_t *jnext;
int found = 0;
@ -527,6 +527,10 @@ int job_reap(bool interactive) {
}
locked = true;
// this may be invoked in an exit handler, after the TERM has been torn down
// don't try to print in that case (#3222)
const bool interactive = allow_interactive && cur_term != NULL;
process_mark_finished_children(false);
// Preserve the exit status.