Use apps_shutdown() in all applications, in case someone decides not
to go the monolith way (does anyone do that these days?).

NOTE: a few applications are missing in this commit.  I've a few more
changes in them that I haven't tested yet.
diff --git a/apps/asn1pars.c b/apps/asn1pars.c
index 108ed7d..4918bcb 100644
--- a/apps/asn1pars.c
+++ b/apps/asn1pars.c
@@ -329,6 +329,7 @@
 	if (at != NULL) ASN1_TYPE_free(at);
 	if (osk != NULL) sk_free(osk);
 	OBJ_cleanup();
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/ciphers.c b/apps/ciphers.c
index c3bd859..2d6e104 100644
--- a/apps/ciphers.c
+++ b/apps/ciphers.c
@@ -202,6 +202,7 @@
 	if (ctx != NULL) SSL_CTX_free(ctx);
 	if (ssl != NULL) SSL_free(ssl);
 	if (STDout != NULL) BIO_free_all(STDout);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/crl.c b/apps/crl.c
index fb36ed5..82ef8ce 100644
--- a/apps/crl.c
+++ b/apps/crl.c
@@ -364,6 +364,7 @@
 		X509_STORE_CTX_cleanup(&ctx);
 		X509_STORE_free(store);
 	}
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/crl2p7.c b/apps/crl2p7.c
index 36d8afe..8729068 100644
--- a/apps/crl2p7.c
+++ b/apps/crl2p7.c
@@ -166,7 +166,8 @@
 		BIO_printf(bio_err," -certfile arg  certificates file of chain to a trusted CA\n");
 		BIO_printf(bio_err,"                (can be used more than once)\n");
 		BIO_printf(bio_err," -nocrl         no crl to load, just certs from '-certfile'\n");
-		EXIT(1);
+		ret = 1;
+		goto end;
 		}
 
 	ERR_load_crypto_strings();
@@ -278,6 +279,7 @@
 	if (p7 != NULL) PKCS7_free(p7);
 	if (crl != NULL) X509_CRL_free(crl);
 
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/dgst.c b/apps/dgst.c
index 1fbef6b..e3edf30 100644
--- a/apps/dgst.c
+++ b/apps/dgst.c
@@ -347,6 +347,7 @@
 	EVP_PKEY_free(sigkey);
 	if(sigbuf) OPENSSL_free(sigbuf);
 	if (bmd != NULL) BIO_free(bmd);
+	apps_shutdown();
 	EXIT(err);
 	}
 
diff --git a/apps/dh.c b/apps/dh.c
index 20581f6..603ea5b 100644
--- a/apps/dh.c
+++ b/apps/dh.c
@@ -330,6 +330,7 @@
 	if (in != NULL) BIO_free(in);
 	if (out != NULL) BIO_free_all(out);
 	if (dh != NULL) DH_free(dh);
+	apps_shutdown();
 	EXIT(ret);
 	}
 #endif
diff --git a/apps/dhparam.c b/apps/dhparam.c
index 51aee97..00cf87b 100644
--- a/apps/dhparam.c
+++ b/apps/dhparam.c
@@ -516,6 +516,7 @@
 	if (in != NULL) BIO_free(in);
 	if (out != NULL) BIO_free_all(out);
 	if (dh != NULL) DH_free(dh);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/dsa.c b/apps/dsa.c
index f18d13d..09ddb23 100644
--- a/apps/dsa.c
+++ b/apps/dsa.c
@@ -304,6 +304,7 @@
 	if(dsa != NULL) DSA_free(dsa);
 	if(passin) OPENSSL_free(passin);
 	if(passout) OPENSSL_free(passout);
+	apps_shutdown();
 	EXIT(ret);
 	}
 #endif
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index 983cd04..4196413 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -368,6 +368,7 @@
 	if (in != NULL) BIO_free(in);
 	if (out != NULL) BIO_free_all(out);
 	if (dsa != NULL) DSA_free(dsa);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/enc.c b/apps/enc.c
index ac3014b..49cae75 100644
--- a/apps/enc.c
+++ b/apps/enc.c
@@ -575,6 +575,7 @@
 	if (benc != NULL) BIO_free(benc);
 	if (b64 != NULL) BIO_free(b64);
 	if(pass) OPENSSL_free(pass);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/engine.c b/apps/engine.c
index 537aefd..1308b6b 100644
--- a/apps/engine.c
+++ b/apps/engine.c
@@ -486,5 +486,6 @@
 	sk_pop_free(pre_cmds, identity);
 	sk_pop_free(post_cmds, identity);
 	if (bio_out != NULL) BIO_free_all(bio_out);
+	apps_shutdown();
 	EXIT(ret);
 	}
diff --git a/apps/errstr.c b/apps/errstr.c
index c411eff..fedb568 100644
--- a/apps/errstr.c
+++ b/apps/errstr.c
@@ -121,5 +121,6 @@
 			ret++;
 			}
 		}
+	apps_shutdown();
 	EXIT(ret);
 	}
diff --git a/apps/gendh.c b/apps/gendh.c
index 14928d8..e8f8493 100644
--- a/apps/gendh.c
+++ b/apps/gendh.c
@@ -195,6 +195,7 @@
 		ERR_print_errors(bio_err);
 	if (out != NULL) BIO_free_all(out);
 	if (dh != NULL) DH_free(dh);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/gendsa.c b/apps/gendsa.c
index 57ef0da..b990eec 100644
--- a/apps/gendsa.c
+++ b/apps/gendsa.c
@@ -231,6 +231,7 @@
 	if (out != NULL) BIO_free_all(out);
 	if (dsa != NULL) DSA_free(dsa);
 	if(passout) OPENSSL_free(passout);
+	apps_shutdown();
 	EXIT(ret);
 	}
 #endif
diff --git a/apps/genrsa.c b/apps/genrsa.c
index dfcb523..a5669de 100644
--- a/apps/genrsa.c
+++ b/apps/genrsa.c
@@ -242,6 +242,7 @@
 	if(passout) OPENSSL_free(passout);
 	if (ret != 0)
 		ERR_print_errors(bio_err);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/passwd.c b/apps/passwd.c
index 750a3cb..5e7195f 100644
--- a/apps/passwd.c
+++ b/apps/passwd.c
@@ -289,6 +289,7 @@
 		BIO_free(in);
 	if (out)
 		BIO_free_all(out);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/pkcs7.c b/apps/pkcs7.c
index f3df25f..a0b2134 100644
--- a/apps/pkcs7.c
+++ b/apps/pkcs7.c
@@ -163,7 +163,8 @@
 		BIO_printf(bio_err," -text         print full details of certificates\n");
 		BIO_printf(bio_err," -noout        don't output encoded data\n");
 		BIO_printf(bio_err," -engine e     use engine e, possibly a hardware device.\n");
-		EXIT(1);
+		ret = 1;
+		goto end;
 		}
 
 	ERR_load_crypto_strings();
@@ -300,5 +301,6 @@
 	if (p7 != NULL) PKCS7_free(p7);
 	if (in != NULL) BIO_free(in);
 	if (out != NULL) BIO_free_all(out);
+	apps_shutdown();
 	EXIT(ret);
 	}
diff --git a/apps/rand.c b/apps/rand.c
index 10adf0e..faba057 100644
--- a/apps/rand.c
+++ b/apps/rand.c
@@ -157,5 +157,6 @@
 	ERR_print_errors(bio_err);
 	if (out)
 		BIO_free_all(out);
+	apps_shutdown();
 	EXIT(ret);
 	}
diff --git a/apps/rsa.c b/apps/rsa.c
index 5b671e1..18964fe 100644
--- a/apps/rsa.c
+++ b/apps/rsa.c
@@ -400,6 +400,7 @@
 	if(rsa != NULL) RSA_free(rsa);
 	if(passin) OPENSSL_free(passin);
 	if(passout) OPENSSL_free(passout);
+	apps_shutdown();
 	EXIT(ret);
 	}
 #else /* !OPENSSL_NO_RSA */
diff --git a/apps/s_client.c b/apps/s_client.c
index 009aa83..ac5d2f1 100644
--- a/apps/s_client.c
+++ b/apps/s_client.c
@@ -803,6 +803,7 @@
 		BIO_free(bio_c_out);
 		bio_c_out=NULL;
 		}
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/s_server.c b/apps/s_server.c
index 11971cb..6ed2349 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -799,6 +799,7 @@
 		BIO_free(bio_s_out);
 		bio_s_out=NULL;
 		}
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/s_time.c b/apps/s_time.c
index 3bdf898..0e2f456 100644
--- a/apps/s_time.c
+++ b/apps/s_time.c
@@ -443,7 +443,6 @@
 
 	if (tm_cipher == NULL ) {
 		fprintf( stderr, "No CIPHER specified\n" );
-/*		EXIT(1); */
 	}
 
 	if (!(perform & 1)) goto next;
@@ -610,6 +609,7 @@
 		SSL_CTX_free(tm_ctx);
 		tm_ctx=NULL;
 		}
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/sess_id.c b/apps/sess_id.c
index 7f5c55b..41c3b3f 100644
--- a/apps/sess_id.c
+++ b/apps/sess_id.c
@@ -272,6 +272,7 @@
 end:
 	if (out != NULL) BIO_free_all(out);
 	if (x != NULL) SSL_SESSION_free(x);
+	apps_shutdown();
 	EXIT(ret);
 	}
 
diff --git a/apps/speed.c b/apps/speed.c
index dbf7732..a7842ce 100644
--- a/apps/speed.c
+++ b/apps/speed.c
@@ -1470,6 +1470,7 @@
 		if (dsa_key[i] != NULL)
 			DSA_free(dsa_key[i]);
 #endif
+	apps_shutdown();
 	EXIT(mret);
 	}
 
diff --git a/apps/version.c b/apps/version.c
index efa0d0d..65b5935 100644
--- a/apps/version.c
+++ b/apps/version.c
@@ -131,5 +131,6 @@
 	if (cflags)  printf("%s\n",SSLeay_version(SSLEAY_CFLAGS));
 	if (dir)  printf("%s\n",SSLeay_version(SSLEAY_DIR));
 end:
+	apps_shutdown();
 	EXIT(ret);
 	}
diff --git a/apps/x509.c b/apps/x509.c
index b2e4ec6..8a392d8 100644
--- a/apps/x509.c
+++ b/apps/x509.c
@@ -1009,6 +1009,7 @@
 	sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);
 	sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free);
 	if (passin) OPENSSL_free(passin);
+	apps_shutdown();
 	EXIT(ret);
 	}