diff --git a/vis-subprocess.c b/vis-subprocess.c index 3fe1dde71..beac99984 100644 --- a/vis-subprocess.c +++ b/vis-subprocess.c @@ -230,3 +230,19 @@ void vis_process_tick(Vis *vis, fd_set *readfds) { } } } + +/** + * Checks if each subprocess from the pool is dead or needs to be + * killed then raises an event or kills it if necessary. + */ +void vis_process_waitall(Vis *vis) { + for (Process **pointer = &process_pool; *pointer; ) { + Process *current = *pointer; + if (!wait_or_kill_process(vis, current)) { + pointer = ¤t->next; + } else { + /* update our iteration pointer */ + *pointer = destroy_process(current); + } + } +} diff --git a/vis-subprocess.h b/vis-subprocess.h index 2e4c22209..79a043e9a 100644 --- a/vis-subprocess.h +++ b/vis-subprocess.h @@ -27,4 +27,5 @@ Process *vis_process_communicate(Vis *, const char *command, const char *name, Invalidator **invalidator); int vis_process_before_tick(fd_set *); void vis_process_tick(Vis *, fd_set *); +void vis_process_waitall(Vis *); #endif diff --git a/vis.c b/vis.c index 10c3df575..d1c0dab08 100644 --- a/vis.c +++ b/vis.c @@ -623,6 +623,7 @@ void vis_free(Vis *vis) { while (vis->windows) vis_window_close(vis->windows); vis_event_emit(vis, VIS_EVENT_QUIT); + vis_process_waitall(vis); file_free(vis, vis->command_file); file_free(vis, vis->search_file); file_free(vis, vis->error_file);