From e3e52394c11e7b9bafa3086e7be937388540daeb Mon Sep 17 00:00:00 2001 From: Anderson Toshiyuki Sasaki Date: Fri, 3 Apr 2020 17:51:53 +0200 Subject: init: Clarify the need to call ssh_{init, finalize}() When libssh is statically linked, it is necessary to explicitly call ssh_init() before calling any other provided API. It is also necessary to call ssh_finalize() before exiting to free allocated resources. Fixes T222 Signed-off-by: Anderson Toshiyuki Sasaki Reviewed-by: Andreas Schneider --- src/init.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/init.c b/src/init.c index 9e70bf65..edecb95e 100644 --- a/src/init.c +++ b/src/init.c @@ -135,14 +135,20 @@ void libssh_constructor(void) /** * @brief Initialize global cryptographic data structures. * - * Since version 0.8.0, it is not necessary to call this function on systems - * which are fully supported with regards to threading (that is, system with - * pthreads available). + * Since version 0.8.0, when libssh is dynamically linked, it is not necessary + * to call this function on systems which are fully supported with regards to + * threading (that is, system with pthreads available). + * + * If libssh is statically linked, it is necessary to explicitly call ssh_init() + * before calling any other provided API, and it is necessary to explicitly call + * ssh_finalize() to free the allocated resources before exiting. * * If the library is already initialized, increments the _ssh_initialized * counter and return the error code cached in _ssh_init_ret. * * @returns SSH_OK on success, SSH_ERROR if an error occurred. + * + * @see ssh_finalize() */ int ssh_init(void) { return _ssh_init(0); @@ -202,8 +208,13 @@ void libssh_destructor(void) /** * @brief Finalize and cleanup all libssh and cryptographic data structures. * - * Since version 0.8.0, it is not necessary to call this function, since it is - * automatically called when the library is unloaded. + * Since version 0.8.0, when libssh is dynamically linked, it is not necessary + * to call this function, since it is automatically called when the library is + * unloaded. + * + * If libssh is statically linked, it is necessary to explicitly call ssh_init() + * before calling any other provided API, and it is necessary to explicitly call + * ssh_finalize() to free the allocated resources before exiting. * * If ssh_init() is called explicitly, then ssh_finalize() must be called * explicitly. @@ -211,9 +222,9 @@ void libssh_destructor(void) * When called, decrements the counter _ssh_initialized. If the counter reaches * zero, then the libssh and cryptographic data structures are cleaned up. * - * @returns 0 on succes, -1 if an error occured. + * @returns 0 on success, -1 if an error occurred. * - @returns 0 otherwise + * @see ssh_init() */ int ssh_finalize(void) { return _ssh_finalize(0); -- cgit v1.2.3