Fix dsaparam -genkey with DER outform
[openssl.git] / apps / rand.c
index e159da37be18e77a34b43b32982f1045d9c0b73e..eddb8af8d70a104b71b8773c5a2557345884c4fc 100644 (file)
@@ -86,9 +86,8 @@ int MAIN(int argc, char **argv)
     int hex = 0;
     BIO *out = NULL;
     int num = -1;
-#ifndef OPENSSL_NO_ENGINE
+    ENGINE *e = NULL;
     char *engine = NULL;
-#endif
 
     apps_startup();
 
@@ -162,9 +161,7 @@ int MAIN(int argc, char **argv)
         BIO_printf(bio_err, "-hex                  - hex encode output\n");
         goto err;
     }
-#ifndef OPENSSL_NO_ENGINE
-    setup_engine(bio_err, engine, 0);
-#endif
+    e = setup_engine(bio_err, engine, 0);
 
     app_RAND_load_file(NULL, bio_err, (inrand != NULL));
     if (inrand != NULL)
@@ -201,7 +198,7 @@ int MAIN(int argc, char **argv)
 
         chunk = num;
         if (chunk > (int)sizeof(buf))
-            chunk = sizeof buf;
+            chunk = sizeof(buf);
         r = RAND_bytes(buf, chunk);
         if (r <= 0)
             goto err;
@@ -222,6 +219,7 @@ int MAIN(int argc, char **argv)
 
  err:
     ERR_print_errors(bio_err);
+    release_engine(e);
     if (out)
         BIO_free_all(out);
     apps_shutdown();