[openssl-dev] [openssl.org #3856] [PATCH] Fix memory leaks in test code

russell.webb@intel.com via RT rt at openssl.org
Thu May 21 16:53:01 UTC 2015


From: Russell Webb <russell.webb at intel.com>

Several tests were not properly cleaning up everything on
process exit, which prevented 'make test' from succeeding
when running with address sanitizer enabled.  Fix the tests
to properly free all resources.

Note that this was found with gcc version 6.0 and was not
observed using gcc 4.9.2.

Signed-off-by: Russell Webb <russell.webb at intel.com>
---
 test/bntest.c   | 1 +
 test/hmactest.c | 3 +++
 test/srptest.c  | 1 +
 3 files changed, 5 insertions(+)

diff --git a/test/bntest.c b/test/bntest.c
index 1ce6db1..891db62 100644
--- a/test/bntest.c
+++ b/test/bntest.c
@@ -1100,6 +1100,7 @@ int test_mod_exp_mont5(BIO *bp, BN_CTX *ctx)
         fprintf(stderr, "Modular exponentiation test failed!\n");
         return 0;
     }
+    BN_MONT_CTX_free(mont);
     BN_free(a);
     BN_free(p);
     BN_free(m);
diff --git a/test/hmactest.c b/test/hmactest.c
index 13344d6..3b01598 100644
--- a/test/hmactest.c
+++ b/test/hmactest.c
@@ -188,6 +188,7 @@ int main(int argc, char *argv[])
     }
     printf("test 4 ok\n");
 test5:
+    HMAC_CTX_cleanup(&ctx);
     HMAC_CTX_init(&ctx);
     if (HMAC_Init_ex(&ctx, test[4].key, test[4].key_len, NULL, NULL)) {
         printf("Should fail to initialise HMAC with empty MD (test 5)\n");
@@ -272,6 +273,7 @@ test5:
         printf("test 5 ok\n");
     }
 test6:
+    HMAC_CTX_cleanup(&ctx);
     HMAC_CTX_init(&ctx);
     if (!HMAC_Init_ex(&ctx, test[7].key, test[7].key_len, EVP_sha1(), NULL)) {
         printf("Failed to initialise HMAC (test 6)\n");
@@ -302,6 +304,7 @@ test6:
         printf("test 6 ok\n");
     }
 end:
+    HMAC_CTX_cleanup(&ctx);
     EXIT(err);
 }
 
diff --git a/test/srptest.c b/test/srptest.c
index 1d463cd..8075218 100644
--- a/test/srptest.c
+++ b/test/srptest.c
@@ -148,6 +148,7 @@ int main(int argc, char **argv)
     ERR_remove_thread_state(NULL);
     ERR_free_strings();
     CRYPTO_mem_leaks(bio_err);
+    BIO_free(bio_err);
 
     return 0;
 }
-- 
2.1.0




More information about the openssl-dev mailing list