--- prime.c.orig	2016-03-08 16:13:24.841500061 -0800
+++ prime.c	2016-03-08 16:15:33.587863062 -0800
@@ -122,6 +122,10 @@
             goto end;
         }
         bn = BN_new();
+	if (bn == NULL) {
+	    BIO_printf(bio_err, "Out of memory\n");
+	    goto end;
+	}
         BN_generate_prime_ex(bn, bits, safe, NULL, NULL, NULL);
         s = hex ? BN_bn2hex(bn) : BN_bn2dec(bn);
         BIO_printf(bio_out, "%s\n", s);
