From 163951d86910eaa7e6ad1a8b08ba85e4c791025c Mon Sep 17 00:00:00 2001 From: Anderson Toshiyuki Sasaki Date: Thu, 30 Jun 2022 13:04:23 +0200 Subject: [PATCH] init: Free global init mutex in the destructor on Windows Fixes: #57 (T238) Signed-off-by: Anderson Toshiyuki Sasaki Reviewed-by: Jakub Jelen --- src/init.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/init.c b/src/init.c index 7fdc14b7..7f184b9c 100644 --- a/src/init.c +++ b/src/init.c @@ -161,12 +161,14 @@ static int _ssh_finalize(unsigned destructor) { if (_ssh_initialized > 1) { _ssh_initialized--; - goto _ret; + ssh_mutex_unlock(&ssh_init_mutex); + return 0; } if (_ssh_initialized == 1) { if (_ssh_init_ret < 0) { - goto _ret; + ssh_mutex_unlock(&ssh_init_mutex); + return 0; } } } @@ -181,10 +183,17 @@ static int _ssh_finalize(unsigned destructor) { _ssh_initialized = 0; -_ret: if (!destructor) { ssh_mutex_unlock(&ssh_init_mutex); } + +#if (defined(_WIN32) && !defined(HAVE_PTHREAD)) + if (ssh_init_mutex != NULL) { + DeleteCriticalSection(ssh_init_mutex); + SAFE_FREE(ssh_init_mutex); + } +#endif + return 0; }