mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-27 13:21:11 +03:00
init: ignore init counter if destructor calls finalize
If the destructor calls finalize, ignore the init counter and finalize the library anyway. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
dbce0e5228
commit
66a3bc0332
30
src/init.c
30
src/init.c
@@ -153,15 +153,20 @@ static int _ssh_finalize(unsigned destructor) {
|
||||
|
||||
if (!destructor) {
|
||||
ssh_mutex_lock(&ssh_init_mutex);
|
||||
}
|
||||
|
||||
if (_ssh_initialized == 1) {
|
||||
_ssh_initialized = 0;
|
||||
|
||||
if (_ssh_init_ret < 0) {
|
||||
if (_ssh_initialized > 1) {
|
||||
_ssh_initialized--;
|
||||
goto _ret;
|
||||
}
|
||||
|
||||
if (_ssh_initialized == 1) {
|
||||
if (_ssh_init_ret < 0) {
|
||||
goto _ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If the counter reaches zero or it is the destructor calling, finalize */
|
||||
ssh_dh_finalize();
|
||||
ssh_crypto_finalize();
|
||||
ssh_socket_cleanup();
|
||||
@@ -169,12 +174,7 @@ static int _ssh_finalize(unsigned destructor) {
|
||||
* it still depends on it */
|
||||
ssh_threads_finalize();
|
||||
|
||||
}
|
||||
else {
|
||||
if (_ssh_initialized > 0) {
|
||||
_ssh_initialized--;
|
||||
}
|
||||
}
|
||||
_ssh_initialized = 0;
|
||||
|
||||
_ret:
|
||||
if (!destructor) {
|
||||
@@ -200,14 +200,6 @@ void libssh_destructor(void)
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error in libssh_destructor()\n");
|
||||
}
|
||||
|
||||
/* Detect if ssh_init() was called without matching ssh_finalize() */
|
||||
if (_ssh_initialized > 0) {
|
||||
fprintf(stderr,
|
||||
"Warning: ssh still initialized; probably ssh_init() "
|
||||
"was called more than once (init count: %d)\n",
|
||||
_ssh_initialized);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user