Finalize OpenSSL context from tests to make the valgrind output clean

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2025-06-03 09:51:11 +02:00
committed by Andreas Schneider
parent 809898b980
commit ab3e08c2b5

View File

@@ -1976,10 +1976,28 @@ __attribute__((weak)) int torture_run_tests(void)
}
#endif /* defined(HAVE_WEAK_ATTRIBUTE) && defined(TORTURE_SHARED) */
/**
* Finalize the torture context. No-op except for OpenSSL.
*
* When OpenSSL is built without the at-exit handlers, it won't call the
* OPENSSL_cleanup() from destructor or at-exit handler, which means we need to
* do it manually in the tests.
*
* It is never a good idea to call this function from the library context as we
* can not be sure the libssh is really the last one using the OpenSSL
*/
static void torture_finalize(void)
{
#ifdef HAVE_LIBCRYPTO
OPENSSL_cleanup();
#endif
}
int main(int argc, char **argv)
{
struct argument_s arguments;
char *env = getenv("LIBSSH_VERBOSITY");
int rv;
arguments.verbose = 0;
arguments.pattern = NULL;
@@ -1997,7 +2015,11 @@ int main(int argc, char **argv)
cmocka_set_test_filter(pattern);
#endif
return torture_run_tests();
rv = torture_run_tests();
torture_finalize();
return rv;
}
/**