[util] Handle double shutdown

If Sys_Shutdown gets called twice, particularly if a shutdown callback
hangs and the program is killed with INT or QUIT, shutdown_list would be
in an invalid state. Thus, get the required data (function pointer and
data pointer) from the list element, then unlink the element before
calling the function. This ensures that a reinvocation of Sys_Shutdown
continues from the next callback or ends cleanly. Fixes a segfault when
killing testsound while using the oss output (it hangs on shutdown).
This commit is contained in:
Bill Currie 2021-06-21 16:41:15 +09:00
parent 770187372d
commit 097d44e270

View file

@ -483,10 +483,13 @@ Sys_Shutdown (void)
shutdown_list_t *t;
while (shutdown_list) {
shutdown_list->func (shutdown_list->data);
void (*func) (void *) = shutdown_list->func;
void *data = shutdown_list->data;
t = shutdown_list;
shutdown_list = shutdown_list->next;
free (t);
func (data);
}
}