[openssl-commits] [openssl] OpenSSL_1_1_0-stable update

Richard Levitte levitte at openssl.org
Thu Oct 20 07:00:06 UTC 2016


The branch OpenSSL_1_1_0-stable has been updated
       via  ec7b16ddbb020b2f49ff7394901cd2b2bed5234b (commit)
       via  a55b3959374161e33c68542d27c0fe93c6b7fe81 (commit)
       via  233bcb95dd7299d98ad235d6ba16c1b5726c9276 (commit)
      from  e7a5f50da09324aeb77386f30cd1110eb5e917f2 (commit)


- Log -----------------------------------------------------------------
commit ec7b16ddbb020b2f49ff7394901cd2b2bed5234b
Author: Richard Levitte <levitte at openssl.org>
Date:   Wed Oct 19 19:49:43 2016 +0200

    apps: remove some #ifndef clutter
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/1643)
    (cherry picked from commit b85bf6395251dc28457b95de586a2f0a5faae4af)

commit a55b3959374161e33c68542d27c0fe93c6b7fe81
Author: Richard Levitte <levitte at openssl.org>
Date:   Wed Oct 19 19:49:22 2016 +0200

    apps: instead of varying implementation, make setup_engine a function always
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/1643)
    (cherry picked from commit 907c6c86331243897b80f37895a14de1e7957541)

commit 233bcb95dd7299d98ad235d6ba16c1b5726c9276
Author: Richard Levitte <levitte at openssl.org>
Date:   Wed Sep 28 23:39:18 2016 +0200

    If an engine comes up explicitely, it must also come down explicitely
    
    In apps/apps.c, one can set up an engine with setup_engine().
    However, we freed the structural reference immediately, which means
    that for engines that don't already have a structural reference
    somewhere else (because it's a built in engine), we end up returning
    an invalid reference.
    
    Instead, the function release_engine() is added, and called at the end
    of the routines that call setup_engine().
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/1643)
    (cherry picked from commit dd1abd4462e4e4fa84b8f8de2ec70375f9b0e191)

-----------------------------------------------------------------------

Summary of changes:
 apps/apps.c      | 14 +++++++++++---
 apps/apps.h      |  6 ++----
 apps/ca.c        |  1 +
 apps/cms.c       |  1 +
 apps/dgst.c      |  1 +
 apps/dhparam.c   |  4 +++-
 apps/dsa.c       |  1 +
 apps/dsaparam.c  |  4 +++-
 apps/ec.c        |  1 +
 apps/ecparam.c   |  6 ++++--
 apps/enc.c       |  4 +++-
 apps/gendsa.c    |  4 +++-
 apps/genpkey.c   |  2 +-
 apps/genrsa.c    |  1 +
 apps/pkcs12.c    |  1 +
 apps/pkcs7.c     |  4 +++-
 apps/pkcs8.c     |  1 +
 apps/pkey.c      |  1 +
 apps/pkeyparam.c |  4 +++-
 apps/pkeyutl.c   |  1 +
 apps/rand.c      |  4 +++-
 apps/req.c       |  1 +
 apps/rsa.c       |  1 +
 apps/rsautl.c    |  1 +
 apps/s_client.c  |  1 +
 apps/s_server.c  |  1 +
 apps/smime.c     |  1 +
 apps/speed.c     |  8 +++-----
 apps/spkac.c     |  1 +
 apps/srp.c       |  4 +++-
 apps/verify.c    |  4 +++-
 apps/x509.c      |  1 +
 32 files changed, 66 insertions(+), 24 deletions(-)

diff --git a/apps/apps.c b/apps/apps.c
index 96184a6..cc557e5 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -1243,11 +1243,13 @@ static ENGINE *try_load_engine(const char *engine)
     }
     return e;
 }
+#endif
 
 ENGINE *setup_engine(const char *engine, int debug)
 {
     ENGINE *e = NULL;
 
+#ifndef OPENSSL_NO_ENGINE
     if (engine) {
         if (strcmp(engine, "auto") == 0) {
             BIO_printf(bio_err, "enabling auto ENGINE support\n");
@@ -1272,13 +1274,19 @@ ENGINE *setup_engine(const char *engine, int debug)
         }
 
         BIO_printf(bio_err, "engine \"%s\" set.\n", ENGINE_get_id(e));
-
-        /* Free our "structural" reference. */
-        ENGINE_free(e);
     }
+#endif
     return e;
 }
+
+void release_engine(ENGINE *e)
+{
+#ifndef OPENSSL_NO_ENGINE
+    if (e != NULL)
+        /* Free our "structural" reference. */
+        ENGINE_free(e);
 #endif
+}
 
 static unsigned long index_serial_hash(const OPENSSL_CSTRING *a)
 {
diff --git a/apps/apps.h b/apps/apps.h
index 27e182c..926a6d6 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -430,11 +430,9 @@ __owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path);
 
 #endif
 
-# ifdef OPENSSL_NO_ENGINE
-#  define setup_engine(engine, debug) NULL
-# else
 ENGINE *setup_engine(const char *engine, int debug);
-# endif
+void release_engine(ENGINE *e);
+
 # ifndef OPENSSL_NO_OCSP
 OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,
                                  const char *host, const char *path,
diff --git a/apps/ca.c b/apps/ca.c
index 34dfd9b..03e08b4 100644
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -1236,6 +1236,7 @@ end_of_options:
     X509_CRL_free(crl);
     NCONF_free(conf);
     NCONF_free(extconf);
+    release_engine(e);
     return (ret);
 }
 
diff --git a/apps/cms.c b/apps/cms.c
index 133dc02..579b227 100644
--- a/apps/cms.c
+++ b/apps/cms.c
@@ -1109,6 +1109,7 @@ int cms_main(int argc, char **argv)
     EVP_PKEY_free(key);
     CMS_ContentInfo_free(cms);
     CMS_ContentInfo_free(rcms);
+    release_engine(e);
     BIO_free(rctin);
     BIO_free(in);
     BIO_free(indata);
diff --git a/apps/dgst.c b/apps/dgst.c
index b10b93e..08182e2 100644
--- a/apps/dgst.c
+++ b/apps/dgst.c
@@ -398,6 +398,7 @@ int dgst_main(int argc, char **argv)
     sk_OPENSSL_STRING_free(macopts);
     OPENSSL_free(sigbuf);
     BIO_free(bmd);
+    release_engine(e);
     return (ret);
 }
 
diff --git a/apps/dhparam.c b/apps/dhparam.c
index ab2e787..2223e1a 100644
--- a/apps/dhparam.c
+++ b/apps/dhparam.c
@@ -70,6 +70,7 @@ int dhparam_main(int argc, char **argv)
     BIO *in = NULL, *out = NULL;
     DH *dh = NULL;
     char *infile = NULL, *outfile = NULL, *prog, *inrand = NULL;
+    ENGINE *e = NULL;
 #ifndef OPENSSL_NO_DSA
     int dsaparam = 0;
 #endif
@@ -104,7 +105,7 @@ int dhparam_main(int argc, char **argv)
             outfile = opt_arg();
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         case OPT_CHECK:
             check = 1;
@@ -356,6 +357,7 @@ int dhparam_main(int argc, char **argv)
     BIO_free(in);
     BIO_free_all(out);
     DH_free(dh);
+    release_engine(e);
     return (ret);
 }
 
diff --git a/apps/dsa.c b/apps/dsa.c
index 6aef502..bfb08e9 100644
--- a/apps/dsa.c
+++ b/apps/dsa.c
@@ -249,6 +249,7 @@ int dsa_main(int argc, char **argv)
  end:
     BIO_free_all(out);
     DSA_free(dsa);
+    release_engine(e);
     OPENSSL_free(passin);
     OPENSSL_free(passout);
     return (ret);
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index 4042660..9258803 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -66,6 +66,7 @@ OPTIONS dsaparam_options[] = {
 
 int dsaparam_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     DSA *dsa = NULL;
     BIO *in = NULL, *out = NULL;
     BN_GENCB *cb = NULL;
@@ -105,7 +106,7 @@ int dsaparam_main(int argc, char **argv)
             outfile = opt_arg();
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         case OPT_TIMEBOMB:
 # ifdef GENCB_TEST
@@ -285,6 +286,7 @@ int dsaparam_main(int argc, char **argv)
     BIO_free(in);
     BIO_free_all(out);
     DSA_free(dsa);
+    release_engine(e);
     return (ret);
 }
 
diff --git a/apps/ec.c b/apps/ec.c
index 007bf0a..2516c03 100644
--- a/apps/ec.c
+++ b/apps/ec.c
@@ -273,6 +273,7 @@ int ec_main(int argc, char **argv)
     BIO_free(in);
     BIO_free_all(out);
     EC_KEY_free(eckey);
+    release_engine(e);
     OPENSSL_free(passin);
     OPENSSL_free(passout);
     return (ret);
diff --git a/apps/ecparam.c b/apps/ecparam.c
index 4e6cf22..891a0ca 100644
--- a/apps/ecparam.c
+++ b/apps/ecparam.c
@@ -87,6 +87,7 @@ static OPT_PAIR encodings[] = {
 
 int ecparam_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     BIGNUM *ec_gen = NULL, *ec_order = NULL, *ec_cofactor = NULL;
     BIGNUM *ec_p = NULL, *ec_a = NULL, *ec_b = NULL;
     BIO *in = NULL, *out = NULL;
@@ -168,7 +169,7 @@ int ecparam_main(int argc, char **argv)
             need_rand = 1;
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         }
     }
@@ -454,9 +455,10 @@ int ecparam_main(int argc, char **argv)
     BN_free(ec_order);
     BN_free(ec_cofactor);
     OPENSSL_free(buffer);
+    EC_GROUP_free(group);
+    release_engine(e);
     BIO_free(in);
     BIO_free_all(out);
-    EC_GROUP_free(group);
     return (ret);
 }
 
diff --git a/apps/enc.c b/apps/enc.c
index 10ab15a..c66ad93 100644
--- a/apps/enc.c
+++ b/apps/enc.c
@@ -82,6 +82,7 @@ int enc_main(int argc, char **argv)
 {
     static char buf[128];
     static const char magic[] = "Salted__";
+    ENGINE *e = NULL;
     BIO *in = NULL, *out = NULL, *b64 = NULL, *benc = NULL, *rbio =
         NULL, *wbio = NULL;
     EVP_CIPHER_CTX *ctx = NULL;
@@ -151,7 +152,7 @@ int enc_main(int argc, char **argv)
             passarg = opt_arg();
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         case OPT_D:
             enc = 0;
@@ -552,6 +553,7 @@ int enc_main(int argc, char **argv)
 #ifdef ZLIB
     BIO_free(bzl);
 #endif
+    release_engine(e);
     OPENSSL_free(pass);
     return (ret);
 }
diff --git a/apps/gendsa.c b/apps/gendsa.c
index 4c05493..bdef022 100644
--- a/apps/gendsa.c
+++ b/apps/gendsa.c
@@ -46,6 +46,7 @@ OPTIONS gendsa_options[] = {
 
 int gendsa_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     BIO *out = NULL, *in = NULL;
     DSA *dsa = NULL;
     const EVP_CIPHER *enc = NULL;
@@ -74,7 +75,7 @@ int gendsa_main(int argc, char **argv)
             passoutarg = opt_arg();
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         case OPT_RAND:
             inrand = opt_arg();
@@ -139,6 +140,7 @@ int gendsa_main(int argc, char **argv)
     BIO_free(in);
     BIO_free_all(out);
     DSA_free(dsa);
+    release_engine(e);
     OPENSSL_free(passout);
     return (ret);
 }
diff --git a/apps/genpkey.c b/apps/genpkey.c
index 7abb3e6..9e37977 100644
--- a/apps/genpkey.c
+++ b/apps/genpkey.c
@@ -193,8 +193,8 @@ int genpkey_main(int argc, char **argv)
     EVP_PKEY_CTX_free(ctx);
     BIO_free_all(out);
     BIO_free(in);
+    release_engine(e);
     OPENSSL_free(pass);
-
     return ret;
 }
 
diff --git a/apps/genrsa.c b/apps/genrsa.c
index 4d104d2..1ac66a9 100644
--- a/apps/genrsa.c
+++ b/apps/genrsa.c
@@ -166,6 +166,7 @@ int genrsa_main(int argc, char **argv)
     BN_GENCB_free(cb);
     RSA_free(rsa);
     BIO_free_all(out);
+    release_engine(eng);
     OPENSSL_free(passout);
     if (ret != 0)
         ERR_print_errors(bio_err);
diff --git a/apps/pkcs12.c b/apps/pkcs12.c
index 93489d6..0e69c9c 100644
--- a/apps/pkcs12.c
+++ b/apps/pkcs12.c
@@ -574,6 +574,7 @@ int pkcs12_main(int argc, char **argv)
     PKCS12_free(p12);
     if (export_cert || inrand)
         app_RAND_write_file(NULL);
+    release_engine(e);
     BIO_free(in);
     BIO_free_all(out);
     sk_OPENSSL_STRING_free(canames);
diff --git a/apps/pkcs7.c b/apps/pkcs7.c
index 85994cd..209e30d 100644
--- a/apps/pkcs7.c
+++ b/apps/pkcs7.c
@@ -44,6 +44,7 @@ OPTIONS pkcs7_options[] = {
 
 int pkcs7_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     PKCS7 *p7 = NULL;
     BIO *in = NULL, *out = NULL;
     int informat = FORMAT_PEM, outformat = FORMAT_PEM;
@@ -90,7 +91,7 @@ int pkcs7_main(int argc, char **argv)
             print_certs = 1;
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         }
     }
@@ -189,6 +190,7 @@ int pkcs7_main(int argc, char **argv)
     ret = 0;
  end:
     PKCS7_free(p7);
+    release_engine(e);
     BIO_free(in);
     BIO_free_all(out);
     return (ret);
diff --git a/apps/pkcs8.c b/apps/pkcs8.c
index 3592a0f..93ffdd5 100644
--- a/apps/pkcs8.c
+++ b/apps/pkcs8.c
@@ -343,6 +343,7 @@ int pkcs8_main(int argc, char **argv)
     X509_SIG_free(p8);
     PKCS8_PRIV_KEY_INFO_free(p8inf);
     EVP_PKEY_free(pkey);
+    release_engine(e);
     BIO_free_all(out);
     BIO_free(in);
     OPENSSL_free(passin);
diff --git a/apps/pkey.c b/apps/pkey.c
index 50ee05f..ad1a3b1 100644
--- a/apps/pkey.c
+++ b/apps/pkey.c
@@ -180,6 +180,7 @@ int pkey_main(int argc, char **argv)
 
  end:
     EVP_PKEY_free(pkey);
+    release_engine(e);
     BIO_free_all(out);
     BIO_free(in);
     OPENSSL_free(passin);
diff --git a/apps/pkeyparam.c b/apps/pkeyparam.c
index f6bcb8f..0a1b2d1 100644
--- a/apps/pkeyparam.c
+++ b/apps/pkeyparam.c
@@ -33,6 +33,7 @@ OPTIONS pkeyparam_options[] = {
 
 int pkeyparam_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     BIO *in = NULL, *out = NULL;
     EVP_PKEY *pkey = NULL;
     int text = 0, noout = 0, ret = 1;
@@ -58,7 +59,7 @@ int pkeyparam_main(int argc, char **argv)
             outfile = opt_arg();
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         case OPT_TEXT:
             text = 1;
@@ -95,6 +96,7 @@ int pkeyparam_main(int argc, char **argv)
 
  end:
     EVP_PKEY_free(pkey);
+    release_engine(e);
     BIO_free_all(out);
     BIO_free(in);
 
diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c
index 02e28e2..962a389 100644
--- a/apps/pkeyutl.c
+++ b/apps/pkeyutl.c
@@ -323,6 +323,7 @@ int pkeyutl_main(int argc, char **argv)
 
  end:
     EVP_PKEY_CTX_free(ctx);
+    release_engine(e);
     BIO_free(in);
     BIO_free_all(out);
     OPENSSL_free(buf_in);
diff --git a/apps/rand.c b/apps/rand.c
index d60f1ec..e726180 100644
--- a/apps/rand.c
+++ b/apps/rand.c
@@ -39,6 +39,7 @@ OPTIONS rand_options[] = {
 
 int rand_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     BIO *out = NULL;
     char *inrand = NULL, *outfile = NULL, *prog;
     OPTION_CHOICE o;
@@ -60,7 +61,7 @@ int rand_main(int argc, char **argv)
             outfile = opt_arg();
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         case OPT_RAND:
             inrand = opt_arg();
@@ -125,6 +126,7 @@ int rand_main(int argc, char **argv)
  end:
     if (ret != 0)
         ERR_print_errors(bio_err);
+    release_engine(e);
     BIO_free_all(out);
     return (ret);
 }
diff --git a/apps/req.c b/apps/req.c
index 8ebe1ec..2707dc9 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -820,6 +820,7 @@ int req_main(int argc, char **argv)
     X509_REQ_free(req);
     X509_free(x509ss);
     ASN1_INTEGER_free(serial);
+    release_engine(e);
     if (passin != nofree_passin)
         OPENSSL_free(passin);
     if (passout != nofree_passout)
diff --git a/apps/rsa.c b/apps/rsa.c
index bd2f53a..c3a494d 100644
--- a/apps/rsa.c
+++ b/apps/rsa.c
@@ -294,6 +294,7 @@ int rsa_main(int argc, char **argv)
     } else
         ret = 0;
  end:
+    release_engine(e);
     BIO_free_all(out);
     RSA_free(rsa);
     OPENSSL_free(passin);
diff --git a/apps/rsautl.c b/apps/rsautl.c
index 84f0164..d527bf4 100644
--- a/apps/rsautl.c
+++ b/apps/rsautl.c
@@ -267,6 +267,7 @@ int rsautl_main(int argc, char **argv)
         BIO_write(out, rsa_out, rsa_outlen);
  end:
     RSA_free(rsa);
+    release_engine(e);
     BIO_free(in);
     BIO_free_all(out);
     OPENSSL_free(rsa_in);
diff --git a/apps/s_client.c b/apps/s_client.c
index 6ec792c..a14d885 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -2485,6 +2485,7 @@ int s_client_main(int argc, char **argv)
     OPENSSL_clear_free(cbuf, BUFSIZZ);
     OPENSSL_clear_free(sbuf, BUFSIZZ);
     OPENSSL_clear_free(mbuf, BUFSIZZ);
+    release_engine(e);
     BIO_free(bio_c_out);
     bio_c_out = NULL;
     BIO_free(bio_c_msg);
diff --git a/apps/s_server.c b/apps/s_server.c
index 2051459..9eb226b 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -1963,6 +1963,7 @@ int s_server_main(int argc, char *argv[])
     ssl_excert_free(exc);
     sk_OPENSSL_STRING_free(ssl_args);
     SSL_CONF_CTX_free(cctx);
+    release_engine(engine);
     BIO_free(bio_s_out);
     bio_s_out = NULL;
     BIO_free(bio_s_msg);
diff --git a/apps/smime.c b/apps/smime.c
index 1f4091f..caa9252 100644
--- a/apps/smime.c
+++ b/apps/smime.c
@@ -614,6 +614,7 @@ int smime_main(int argc, char **argv)
     X509_free(signer);
     EVP_PKEY_free(key);
     PKCS7_free(p7);
+    release_engine(e);
     BIO_free(in);
     BIO_free(indata);
     BIO_free_all(out);
diff --git a/apps/speed.c b/apps/speed.c
index e6bdc5d..cdd0da1 100644
--- a/apps/speed.c
+++ b/apps/speed.c
@@ -1219,13 +1219,12 @@ static int run_benchmark(int async_jobs,
 
 int speed_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     loopargs_t *loopargs = NULL;
     int async_init = 0;
     int loopargs_len = 0;
     char *prog;
-#ifndef OPENSSL_NO_ENGINE
     const char *engine_id = NULL;
-#endif
     const EVP_CIPHER *evp_cipher = NULL;
     double d = 0.0;
     OPTION_CHOICE o;
@@ -1399,9 +1398,7 @@ int speed_main(int argc, char **argv)
              * initialised by each child process, not by the parent.
              * So store the name here and run setup_engine() later on.
              */
-#ifndef OPENSSL_NO_ENGINE
             engine_id = opt_arg();
-#endif
             break;
         case OPT_MULTI:
 #ifndef NO_FORK
@@ -1566,7 +1563,7 @@ int speed_main(int argc, char **argv)
 #endif
 
     /* Initialize the engine after the fork */
-    (void)setup_engine(engine_id, 0);
+    e = setup_engine(engine_id, 0);
 
     /* No parameters; turn on everything. */
     if ((argc == 0) && !doit[D_EVP]) {
@@ -2819,6 +2816,7 @@ int speed_main(int argc, char **argv)
         ASYNC_cleanup_thread();
     }
     OPENSSL_free(loopargs);
+    release_engine(e);
     return (ret);
 }
 
diff --git a/apps/spkac.c b/apps/spkac.c
index c65103d..90a5bea 100644
--- a/apps/spkac.c
+++ b/apps/spkac.c
@@ -187,6 +187,7 @@ int spkac_main(int argc, char **argv)
     NETSCAPE_SPKI_free(spki);
     BIO_free_all(out);
     EVP_PKEY_free(pkey);
+    release_engine(e);
     OPENSSL_free(passin);
     return (ret);
 }
diff --git a/apps/srp.c b/apps/srp.c
index 69175eb..add0100 100644
--- a/apps/srp.c
+++ b/apps/srp.c
@@ -209,6 +209,7 @@ OPTIONS srp_options[] = {
 
 int srp_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     CA_DB *db = NULL;
     CONF *conf = NULL;
     int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;
@@ -269,7 +270,7 @@ int srp_main(int argc, char **argv)
             passoutarg = opt_arg();
             break;
         case OPT_ENGINE:
-            (void)setup_engine(opt_arg(), 0);
+            e = setup_engine(opt_arg(), 0);
             break;
         }
     }
@@ -602,6 +603,7 @@ int srp_main(int argc, char **argv)
         app_RAND_write_file(randfile);
     NCONF_free(conf);
     free_index(db);
+    release_engine(e);
     return (ret);
 }
 #endif
diff --git a/apps/verify.c b/apps/verify.c
index 47a8c86..3c45663 100644
--- a/apps/verify.c
+++ b/apps/verify.c
@@ -60,6 +60,7 @@ OPTIONS verify_options[] = {
 
 int verify_main(int argc, char **argv)
 {
+    ENGINE *e = NULL;
     STACK_OF(X509) *untrusted = NULL, *trusted = NULL;
     STACK_OF(X509_CRL) *crls = NULL;
     X509_STORE *store = NULL;
@@ -140,7 +141,7 @@ int verify_main(int argc, char **argv)
             crl_download = 1;
             break;
         case OPT_ENGINE:
-            if (setup_engine(opt_arg(), 0) == NULL) {
+            if ((e = setup_engine(opt_arg(), 0)) == NULL) {
                 /* Failure message already displayed */
                 goto end;
             }
@@ -191,6 +192,7 @@ int verify_main(int argc, char **argv)
     sk_X509_pop_free(untrusted, X509_free);
     sk_X509_pop_free(trusted, X509_free);
     sk_X509_CRL_pop_free(crls, X509_CRL_free);
+    release_engine(e);
     return (ret < 0 ? 2 : ret);
 }
 
diff --git a/apps/x509.c b/apps/x509.c
index 3539602..577c35d 100644
--- a/apps/x509.c
+++ b/apps/x509.c
@@ -893,6 +893,7 @@ int x509_main(int argc, char **argv)
     sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);
     sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free);
     ASN1_OBJECT_free(objtmp);
+    release_engine(e);
     OPENSSL_free(passin);
     return (ret);
 }


More information about the openssl-commits mailing list