Fix leaks and give an error if no argument specified in prime.c
authorDr. Stephen Henson <steve@openssl.org>
Sat, 27 Nov 2004 12:55:26 +0000 (12:55 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 27 Nov 2004 12:55:26 +0000 (12:55 +0000)
apps/prime.c

index 5c731a7e015c23ecc21894fa55f1b1203bdb9540..5e3333bc4a72d74e29a27e3f50d1ecfb931c3aec 100644 (file)
@@ -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 <n>");
-           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 <n>");
+    exit(1);
     }