Move malloc fail checks closer to malloc
authorMatt Caswell <matt@openssl.org>
Thu, 12 Mar 2015 11:25:03 +0000 (11:25 +0000)
committerMatt Caswell <matt@openssl.org>
Tue, 17 Mar 2015 13:49:31 +0000 (13:49 +0000)
Move memory allocation failure checks closer to the site of the malloc in
dgst app. Only a problem if the debug flag is set...but still should be
fixed.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(cherry picked from commit be1477adc97e76f4b83ed8075589f529069bd5d1)

apps/dgst.c

index 8459c19625a0c0e1b572d58c44d189e57cb11a1e..ad2f2348ac09c963ae1df5d8a1f08bb78fd4598e 100644 (file)
@@ -287,6 +287,11 @@ int MAIN(int argc, char **argv)
 
     in = BIO_new(BIO_s_file());
     bmd = BIO_new(BIO_f_md());
+    if ((in == NULL) || (bmd == NULL)) {
+        ERR_print_errors(bio_err);
+        goto end;
+    }
+
     if (debug) {
         BIO_set_callback(in, BIO_debug_callback);
         /* needed for windows 3.1 */
@@ -298,11 +303,6 @@ int MAIN(int argc, char **argv)
         goto end;
     }
 
-    if ((in == NULL) || (bmd == NULL)) {
-        ERR_print_errors(bio_err);
-        goto end;
-    }
-
     if (out_bin == -1) {
         if (keyfile)
             out_bin = 1;