From e4d224d23970741f52ba374e2a4b103b1ce43a59 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Fri, 17 Nov 2023 13:49:48 +0100 Subject: [PATCH] Improve shutdown 1. close logfile as last action 2. Fix `plugins_shutdown()` accessing `((ProfPlugin*)curr->data)->lang` after `curr->data` had already potentially been free'd. Signed-off-by: Steffen Jaeckel --- src/plugins/plugins.c | 12 +++++++----- src/profanity.c | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 3b64c7aa..274b711e 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -932,21 +932,23 @@ void plugins_shutdown(void) { GList* values = g_hash_table_get_values(plugins); - GList* curr = values; + GList *curr = values, *next; while (curr) { + next = g_list_next(curr); #ifdef HAVE_PYTHON - if (((ProfPlugin*)curr->data)->lang == LANG_PYTHON) { + if (curr && ((ProfPlugin*)curr->data)->lang == LANG_PYTHON) { python_plugin_destroy(curr->data); + curr = NULL; } #endif #ifdef HAVE_C - if (((ProfPlugin*)curr->data)->lang == LANG_C) { + if (curr && ((ProfPlugin*)curr->data)->lang == LANG_C) { c_plugin_destroy(curr->data); + curr = NULL; } #endif - - curr = g_list_next(curr); + curr = next; } g_list_free(values); #ifdef HAVE_PYTHON diff --git a/src/profanity.c b/src/profanity.c index 0731d711..9660945c 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -256,9 +256,9 @@ _shutdown(void) accounts_close(); tlscerts_close(); log_stderr_close(); - log_close(); plugins_shutdown(); cmd_uninit(); ui_close(); prefs_close(); + log_close(); }