[console] Unhook hooked functions on shutdown

Forgetting to unhook the functions (Sys_Printf and the client console's
input event handler) was not a problem for static builds because the
functions were always present, but in builds with dynamic plugins, the
client console's code got ripped away and thus Sys_Printf and the event
hander were being sent into invalid memory. Too much work, not enough
play (with a fully installed client).
This commit is contained in:
Bill Currie 2021-12-29 21:50:38 +09:00
parent 760256c99e
commit 3c17efe91b
3 changed files with 13 additions and 1 deletions

View File

@ -952,6 +952,7 @@ C_Init (void)
static void
C_shutdown (void)
{
IE_Remove_Handler (con_event_id);
}
static general_funcs_t plugin_info_general_funcs = {

View File

@ -57,6 +57,7 @@ static U void (*const display)(const char **, int) = Con_DisplayList;
#undef U
static cvar_t *con_interpreter;
static sys_printf_t saved_sys_printf;
static void
Con_Interp_f (cvar_t *var)
@ -89,6 +90,9 @@ Con_Interp_f (cvar_t *var)
static void
Con_shutdown (void *data)
{
if (saved_sys_printf) {
Sys_SetStdPrintf (saved_sys_printf);
}
if (con_module) {
con_module->functions->general->shutdown ();
PI_UnloadPlugin (con_module);
@ -102,7 +106,8 @@ Con_Init (const char *plugin_name)
con_module = PI_LoadPlugin ("console", plugin_name);
if (con_module) {
Sys_SetStdPrintf (con_module->functions->console->print);
__auto_type funcs = con_module->functions->console;
saved_sys_printf = Sys_SetStdPrintf (funcs->print);
} else {
setvbuf (stdout, 0, _IOLBF, BUFSIZ);
}

View File

@ -247,6 +247,9 @@ VISIBLE sys_printf_t
Sys_SetStdPrintf (sys_printf_t func)
{
sys_printf_t prev = sys_std_printf_function;
if (!func) {
func = Sys_StdPrintf;
}
sys_std_printf_function = func;
return prev;
}
@ -255,6 +258,9 @@ VISIBLE sys_printf_t
Sys_SetErrPrintf (sys_printf_t func)
{
sys_printf_t prev = sys_err_printf_function;
if (!func) {
func = Sys_ErrPrintf;
}
sys_err_printf_function = func;
return prev;
}