From 62d10c2a38160ef539a784b96960a6b5e3d8d6b6 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Mon, 27 Jun 2016 17:56:18 +0200 Subject: [PATCH] tests: Fix trivial memory leaks. -- Signed-off-by: Justus Winter --- tests/gpg/t-decrypt-verify.c | 3 ++- tests/gpg/t-decrypt.c | 3 ++- tests/gpg/t-encrypt-sym.c | 1 + tests/gpg/t-import.c | 6 ++++-- tests/gpg/t-thread1.c | 3 ++- tests/gpgsm/t-import.c | 6 ++++-- tests/gpgsm/t-keylist.c | 1 + tests/t-data.c | 9 ++++++--- 8 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/gpg/t-decrypt-verify.c b/tests/gpg/t-decrypt-verify.c index 0d89669e..823655fc 100644 --- a/tests/gpg/t-decrypt-verify.c +++ b/tests/gpg/t-decrypt-verify.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) gpgme_data_t in, out; gpgme_decrypt_result_t decrypt_result; gpgme_verify_result_t verify_result; - const char *cipher_2_asc = make_filename ("cipher-2.asc"); + char *cipher_2_asc = make_filename ("cipher-2.asc"); char *agent_info; init_gpgme (GPGME_PROTOCOL_OpenPGP); @@ -114,6 +114,7 @@ main (int argc, char *argv[]) gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); err = gpgme_data_new_from_file (&in, cipher_2_asc, 1); + free (cipher_2_asc); fail_if_err (err); err = gpgme_data_new (&out); fail_if_err (err); diff --git a/tests/gpg/t-decrypt.c b/tests/gpg/t-decrypt.c index 2a2f4d7b..b085e048 100644 --- a/tests/gpg/t-decrypt.c +++ b/tests/gpg/t-decrypt.c @@ -43,7 +43,7 @@ main (int argc, char *argv[]) gpgme_error_t err; gpgme_data_t in, out; gpgme_decrypt_result_t result; - const char *cipher_1_asc = make_filename ("cipher-1.asc"); + char *cipher_1_asc = make_filename ("cipher-1.asc"); char *agent_info; init_gpgme (GPGME_PROTOCOL_OpenPGP); @@ -56,6 +56,7 @@ main (int argc, char *argv[]) gpgme_set_passphrase_cb (ctx, passphrase_cb, NULL); err = gpgme_data_new_from_file (&in, cipher_1_asc, 1); + free (cipher_1_asc); fail_if_err (err); err = gpgme_data_new (&out); diff --git a/tests/gpg/t-encrypt-sym.c b/tests/gpg/t-encrypt-sym.c index 51a3fc1b..42dc3ca4 100644 --- a/tests/gpg/t-encrypt-sym.c +++ b/tests/gpg/t-encrypt-sym.c @@ -92,6 +92,7 @@ main (int argc, char *argv[]) } gpgme_data_release (cipher); + free (text2); gpgme_release (ctx); return 0; diff --git a/tests/gpg/t-import.c b/tests/gpg/t-import.c index d673f870..41cfd233 100644 --- a/tests/gpg/t-import.c +++ b/tests/gpg/t-import.c @@ -214,8 +214,8 @@ main (int argc, char *argv[]) gpgme_error_t err; gpgme_data_t in; gpgme_import_result_t result; - const char *pubkey_1_asc = make_filename ("pubkey-1.asc"); - const char *seckey_1_asc = make_filename ("seckey-1.asc"); + char *pubkey_1_asc = make_filename ("pubkey-1.asc"); + char *seckey_1_asc = make_filename ("seckey-1.asc"); init_gpgme (GPGME_PROTOCOL_OpenPGP); @@ -223,6 +223,7 @@ main (int argc, char *argv[]) fail_if_err (err); err = gpgme_data_new_from_file (&in, pubkey_1_asc, 1); + free (pubkey_1_asc); fail_if_err (err); err = gpgme_op_import (ctx, in); @@ -232,6 +233,7 @@ main (int argc, char *argv[]) gpgme_data_release (in); err = gpgme_data_new_from_file (&in, seckey_1_asc, 1); + free (seckey_1_asc); fail_if_err (err); err = gpgme_op_import (ctx, in); diff --git a/tests/gpg/t-thread1.c b/tests/gpg/t-thread1.c index 86ea51af..0d4b2deb 100644 --- a/tests/gpg/t-thread1.c +++ b/tests/gpg/t-thread1.c @@ -94,7 +94,7 @@ void * thread_two (void *name) { int i; - const char *cipher_1_asc = make_filename ("cipher-1.asc"); + char *cipher_1_asc = make_filename ("cipher-1.asc"); char *agent_info; agent_info = getenv("GPG_AGENT_INFO"); @@ -135,6 +135,7 @@ thread_two (void *name) gpgme_data_release (out); gpgme_release (ctx); } + free (cipher_1_asc); return NULL; } diff --git a/tests/gpgsm/t-import.c b/tests/gpgsm/t-import.c index 2d23779e..adfebaaa 100644 --- a/tests/gpgsm/t-import.c +++ b/tests/gpgsm/t-import.c @@ -142,8 +142,8 @@ main (int argc, char **argv) gpgme_error_t err; gpgme_data_t in; gpgme_import_result_t result; - const char *cert_1 = make_filename ("cert_dfn_pca01.der"); - const char *cert_2 = make_filename ("cert_dfn_pca15.der"); + char *cert_1 = make_filename ("cert_dfn_pca01.der"); + char *cert_2 = make_filename ("cert_dfn_pca15.der"); init_gpgme (GPGME_PROTOCOL_CMS); @@ -153,6 +153,7 @@ main (int argc, char **argv) gpgme_set_protocol (ctx, GPGME_PROTOCOL_CMS); err = gpgme_data_new_from_file (&in, cert_1, 1); + free (cert_1); fail_if_err (err); err = gpgme_op_import (ctx, in); @@ -162,6 +163,7 @@ main (int argc, char **argv) gpgme_data_release (in); err = gpgme_data_new_from_file (&in, cert_2, 1); + free (cert_2); fail_if_err (err); err = gpgme_op_import (ctx, in); diff --git a/tests/gpgsm/t-keylist.c b/tests/gpgsm/t-keylist.c index bebd9d6a..5204ab2e 100644 --- a/tests/gpgsm/t-keylist.c +++ b/tests/gpgsm/t-keylist.c @@ -110,6 +110,7 @@ main (int argc, char **argv) { fprintf (stderr, "Warning: Skipping unknown key %s\n", key->subkeys->fpr); + gpgme_key_unref (key); continue; } else diff --git a/tests/t-data.c b/tests/t-data.c index 465f29ee..178675c9 100644 --- a/tests/t-data.c +++ b/tests/t-data.c @@ -194,8 +194,8 @@ int main (int argc, char **argv) { round_t round = TEST_INITIALIZER; - const char *text_filename = make_filename ("t-data-1.txt"); - const char *longer_text_filename = make_filename ("t-data-2.txt"); + char *text_filename = make_filename ("t-data-1.txt"); + char *longer_text_filename = make_filename ("t-data-2.txt"); const char *missing_filename = "this-file-surely-does-not-exist"; gpgme_error_t err = 0; gpgme_data_t data; @@ -269,7 +269,7 @@ main (int argc, char **argv) } break; case TEST_END: - return 0; + goto out; case TEST_INITIALIZER: /* Shouldn't happen. */ fprintf (stderr, "%s:%d: impossible condition\n", __FILE__, __LINE__); @@ -281,5 +281,8 @@ main (int argc, char **argv) write_test (round, data); gpgme_data_release (data); } + out: + free (text_filename); + free (longer_text_filename); return 0; }