diff options
author | Jack Lloyd <[email protected]> | 2016-02-09 06:51:03 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-02-09 06:54:04 -0500 |
commit | 32753defe9e49ba7dac457210ee0617313cb1b7b (patch) | |
tree | 29d9bd0641a9b4df213ac1cde52ce6cc27c24290 /src | |
parent | 46e9a8998e29cbf357b79123934434b2ea081e4b (diff) |
Fix memory leaks in FFI tests
Some tests only deallocated in the branch where some other test
on the object succeeded.
The ECDH FFI test didn't deallocate any of its objects, which was
missed by valgrind before now because the test was not being run.
Found by Coverity scanner
Diffstat (limited to 'src')
-rw-r--r-- | src/tests/test_ffi.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/tests/test_ffi.cpp b/src/tests/test_ffi.cpp index dd0293949..77beaf855 100644 --- a/src/tests/test_ffi.cpp +++ b/src/tests/test_ffi.cpp @@ -107,8 +107,9 @@ class FFI_Unit_Tests : public Test result.test_eq("SHA-256 output", outbuf, "B5D4045C3F466FA91FE2CC6ABE79232A1A57CDF104F7A26E716E0A1E2789DF78"); } - TEST_FFI_OK(botan_hash_destroy, (hash)); } + + TEST_FFI_OK(botan_hash_destroy, (hash)); } // MAC test @@ -142,9 +143,9 @@ class FFI_Unit_Tests : public Test TEST_FFI_OK(botan_mac_final, (mac, outbuf.data())); result.test_eq("HMAC output", outbuf, "1A82EEA984BC4A7285617CC0D05F1FE1D6C96675924A81BC965EE8FF7B0697A7"); - - TEST_FFI_OK(botan_mac_destroy, (mac)); } + + TEST_FFI_OK(botan_mac_destroy, (mac)); } const std::vector<uint8_t> pbkdf_salt = Botan::hex_decode("ED1F39A0A7F3889AAF7E60743B3BC1CC2C738E60"); @@ -208,6 +209,7 @@ class FFI_Unit_Tests : public Test std::vector<Test::Result> results; results.push_back(ffi_test_rsa(rng)); results.push_back(ffi_test_ecdsa(rng)); + results.push_back(ffi_test_ecdh(rng)); TEST_FFI_OK(botan_rng_destroy, (rng)); @@ -249,8 +251,6 @@ class FFI_Unit_Tests : public Test { ciphertext.resize(ctext_len); - TEST_FFI_OK(botan_pk_op_encrypt_destroy, (encrypt)); - botan_pk_op_decrypt_t decrypt; if(TEST_FFI_OK(botan_pk_op_decrypt_create, (&decrypt, priv, "OAEP(SHA-256)", 0))) { @@ -261,10 +261,12 @@ class FFI_Unit_Tests : public Test decrypted.resize(decrypted_len); result.test_eq("RSA plaintext", decrypted, plaintext); - - TEST_FFI_OK(botan_pk_op_decrypt_destroy, (decrypt)); } + + TEST_FFI_OK(botan_pk_op_decrypt_destroy, (decrypt)); } + + TEST_FFI_OK(botan_pk_op_encrypt_destroy, (encrypt)); } TEST_FFI_OK(botan_pubkey_destroy, (pub)); @@ -393,6 +395,13 @@ class FFI_Unit_Tests : public Test result.test_eq("shared ECDH key", key1, key2); + TEST_FFI_OK(botan_pk_op_key_agreement_destroy, (ka1)); + TEST_FFI_OK(botan_pk_op_key_agreement_destroy, (ka2)); + TEST_FFI_OK(botan_privkey_destroy, (priv1)); + TEST_FFI_OK(botan_privkey_destroy, (priv2)); + TEST_FFI_OK(botan_pubkey_destroy, (pub1)); + TEST_FFI_OK(botan_pubkey_destroy, (pub2)); + return result; } }; |