Fix some mem leaks in sslapitest
authorMatt Caswell <matt@openssl.org>
Mon, 26 Sep 2016 11:04:23 +0000 (12:04 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 26 Sep 2016 16:26:50 +0000 (17:26 +0100)
A mem leak could occur on an error path. Also the mempacket BIO_METHOD
needs to be cleaned up, because of the newly added DTLS test.

Also fixed a double semi-colon in ssltestlib.c

Reviewed-by: Rich Salz <rsalz@openssl.org>
test/sslapitest.c
test/ssltestlib.c

index acb2087cc4fd8421291502d25d753fe3adc4842f..b08eb8c78f0bca0eab965dabae5c9d9e124a7e5a 100644 (file)
@@ -46,14 +46,18 @@ static int execute_test_large_message(const SSL_METHOD *smeth,
         goto end;
     }
     chaincert = PEM_read_bio_X509(certbio, NULL, NULL, NULL);
+    BIO_free(certbio);
+    certbio = NULL;
+    if (chaincert == NULL) {
+        printf("Unable to load certificate for chain\n");
+        goto end;
+    }
 
     if (!create_ssl_ctx_pair(smeth, cmeth, &sctx,
                              &cctx, cert, privkey)) {
         printf("Unable to create SSL_CTX pair\n");
         goto end;
     }
-    BIO_free(certbio);
-    certbio = NULL;
 
     /*
      * We assume the supplied certificate is big enough so that if we add
@@ -870,6 +874,8 @@ int main(int argc, char *argv[])
 
     testresult = run_tests(argv[0]);
 
+    bio_s_mempacket_test_free();
+
 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
     if (CRYPTO_mem_leaks(err) <= 0)
         testresult = 1;
index 9fcd98de7de096d3373d0a6079d8bfdceb542b9f..655fc05cb2a696e2aba0d808a136c6f25001b7eb 100644 (file)
@@ -587,7 +587,7 @@ int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
 
     if (SSL_is_dtls(clientssl)) {
         s_to_c_bio = BIO_new(bio_s_mempacket_test());
-        c_to_s_bio = BIO_new(bio_s_mempacket_test());;
+        c_to_s_bio = BIO_new(bio_s_mempacket_test());
     } else {
         s_to_c_bio = BIO_new(BIO_s_mem());
         c_to_s_bio = BIO_new(BIO_s_mem());