From 3e0c2275ef2aefb4075a764169cc2d820d633820 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Tue, 2 Jul 2024 13:30:04 +0200 Subject: [PATCH] tests: Avoid memory leaks from tests Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- tests/client/torture_auth_pkcs11.c | 7 ++----- tests/unittests/torture_pki_rsa_uri.c | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/client/torture_auth_pkcs11.c b/tests/client/torture_auth_pkcs11.c index 2537d2d8..63c1aff6 100644 --- a/tests/client/torture_auth_pkcs11.c +++ b/tests/client/torture_auth_pkcs11.c @@ -116,7 +116,7 @@ static int setup_session(void **state) s->private_data = test_state; - test_state->orig_dir = strdup(torture_get_current_working_dir()); + test_state->orig_dir = torture_get_current_working_dir(); assert_non_null(test_state->orig_dir); temp_dir = torture_make_temp_dir(template); @@ -125,7 +125,7 @@ static int setup_session(void **state) rc = torture_change_dir(temp_dir); assert_int_equal(rc, 0); - test_state->temp_dir = strdup(torture_get_current_working_dir()); + test_state->temp_dir = torture_get_current_working_dir(); assert_non_null(test_state->temp_dir); snprintf(keys_dir, sizeof(keys_dir), "%s/tests/keys/pkcs11/", SOURCEDIR); @@ -240,9 +240,6 @@ int torture_run_tests(void) { session_teardown), }; - ssh_session session = ssh_new(); - int verbosity = SSH_LOG_FUNCTIONS; - ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); ssh_init(); torture_filter_tests(tests); rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown); diff --git a/tests/unittests/torture_pki_rsa_uri.c b/tests/unittests/torture_pki_rsa_uri.c index 46c9a083..d57a002d 100644 --- a/tests/unittests/torture_pki_rsa_uri.c +++ b/tests/unittests/torture_pki_rsa_uri.c @@ -89,7 +89,7 @@ static int setup_tokens(void **state) static int setup_directory_structure(void **state) { struct pki_st *test_state = NULL; - char *temp_dir; + char *temp_dir = NULL; int rc; test_state = (struct pki_st *)malloc(sizeof(struct pki_st)); @@ -103,6 +103,7 @@ static int setup_directory_structure(void **state) rc = torture_change_dir(temp_dir); assert_int_equal(rc, 0); + free(temp_dir); test_state->temp_dir = torture_get_current_working_dir(); assert_non_null(test_state->temp_dir);