From 097d44e2709bb2d095197dca3372219a848da250 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 21 Jun 2021 16:41:15 +0900 Subject: [PATCH] [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). --- libs/util/sys.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/util/sys.c b/libs/util/sys.c index 8758f270a..87241a8c1 100644 --- a/libs/util/sys.c +++ b/libs/util/sys.c @@ -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); } }