From 18ad97bbe710ec8a3bd89f45ea7f2edb76fdce50 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 27 Nov 2004 12:55:26 +0000 Subject: [PATCH] Fix leaks and give an error if no argument specified in prime.c --- apps/prime.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/apps/prime.c b/apps/prime.c index 5c731a7e01..5e3333bc4a 100644 --- a/apps/prime.c +++ b/apps/prime.c @@ -69,18 +69,6 @@ int MAIN(int argc, char **argv) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); - if (bio_out == NULL) - if ((bio_out=BIO_new(BIO_s_file())) != NULL) - { - BIO_set_fp(bio_out,stdout,BIO_NOCLOSE); -#ifdef OPENSSL_SYS_VMS - { - BIO *tmpbio = BIO_new(BIO_f_linebuffer()); - bio_out = BIO_push(tmpbio, bio_out); - } -#endif - } - --argc; ++argv; while (argc >= 1 && **argv == '-') @@ -95,16 +83,30 @@ int MAIN(int argc, char **argv) else { BIO_printf(bio_err,"Unknown option '%s'\n",*argv); - bad: - BIO_printf(bio_err,"options are\n"); - BIO_printf(bio_err,"%-14s hex\n","-hex"); - BIO_printf(bio_err,"%-14s number of checks\n","-checks "); - exit(1); + goto bad; } --argc; ++argv; } + if (argv[0] == NULL) + { + BIO_printf(bio_err,"No prime specified\n"); + goto bad; + } + + if (bio_out == NULL) + if ((bio_out=BIO_new(BIO_s_file())) != NULL) + { + BIO_set_fp(bio_out,stdout,BIO_NOCLOSE); +#ifdef OPENSSL_SYS_VMS + { + BIO *tmpbio = BIO_new(BIO_f_linebuffer()); + bio_out = BIO_push(tmpbio, bio_out); + } +#endif + } + if(hex) BN_hex2bn(&bn,argv[0]); else @@ -114,5 +116,14 @@ int MAIN(int argc, char **argv) BIO_printf(bio_out," is %sprime\n", BN_is_prime(bn,checks,NULL,NULL,NULL) ? "" : "not "); + BN_free(bn); + BIO_free(bio_out); + return 0; + + bad: + BIO_printf(bio_err,"options are\n"); + BIO_printf(bio_err,"%-14s hex\n","-hex"); + BIO_printf(bio_err,"%-14s number of checks\n","-checks "); + exit(1); } -- 2.25.1