Make OPENSSL_malloc push ERR_R_MALLOC_FAILURE on failure.

Remove all the other ERR_R_MALLOC_FAILURES from the
codebase.

Also changes cbb to push to the error stack, to correctly
report cbb failures instead of now only reporting
malloc failures. Previously it turned all cbb failures
into a malloc failure

Bug: 564

Change-Id: Ic13208bf9d9aaa470e83b2f15782fc94946bbc7b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/57046
Auto-Submit: Bob Beck <bbe@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c
index 3d60d3b..2be07a4 100644
--- a/crypto/asn1/a_bitstr.c
+++ b/crypto/asn1/a_bitstr.c
@@ -184,7 +184,6 @@
   if (len > 0) {
     s = OPENSSL_memdup(p, len);
     if (s == NULL) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     p += len;
@@ -236,7 +235,6 @@
       c = (unsigned char *)OPENSSL_realloc(a->data, w + 1);
     }
     if (c == NULL) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     if (w + 1 - a->length > 0) {
diff --git a/crypto/asn1/a_bool.c b/crypto/asn1/a_bool.c
index 8dc84d4..67d6813 100644
--- a/crypto/asn1/a_bool.c
+++ b/crypto/asn1/a_bool.c
@@ -70,7 +70,6 @@
 
   if (*pp == NULL) {
     if ((p = allocated = OPENSSL_malloc(r)) == NULL) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       return -1;
     }
   } else {
diff --git a/crypto/asn1/a_dup.c b/crypto/asn1/a_dup.c
index 8ee0c7e..b37a5c6 100644
--- a/crypto/asn1/a_dup.c
+++ b/crypto/asn1/a_dup.c
@@ -75,7 +75,6 @@
 
   i = ASN1_item_i2d(x, &b, it);
   if (b == NULL) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   p = b;
diff --git a/crypto/asn1/a_i2d_fp.c b/crypto/asn1/a_i2d_fp.c
index 4a14f2b..e0713fa 100644
--- a/crypto/asn1/a_i2d_fp.c
+++ b/crypto/asn1/a_i2d_fp.c
@@ -76,7 +76,6 @@
   unsigned char *b = NULL;
   int n = ASN1_item_i2d(x, &b, it);
   if (b == NULL) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c
index e1a3df2..80cfac4 100644
--- a/crypto/asn1/a_mbstr.c
+++ b/crypto/asn1/a_mbstr.c
@@ -218,7 +218,6 @@
     free_dest = 1;
     dest = ASN1_STRING_type_new(str_type);
     if (!dest) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       return -1;
     }
   }
@@ -226,7 +225,6 @@
   // If both the same type just copy across
   if (inform == outform) {
     if (!ASN1_STRING_set(dest, in, len)) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     dest->type = str_type;
@@ -236,7 +234,6 @@
 
   CBB cbb;
   if (!CBB_init(&cbb, size_estimate + 1)) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   CBS_init(&cbs, in, len);
diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c
index 8c420c6..56219e1 100644
--- a/crypto/asn1/a_object.c
+++ b/crypto/asn1/a_object.c
@@ -86,7 +86,6 @@
   unsigned char *p, *allocated = NULL;
   if (*pp == NULL) {
     if ((p = allocated = OPENSSL_malloc(objsize)) == NULL) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       return -1;
     }
   } else {
@@ -211,7 +210,6 @@
     OPENSSL_free(data);
     data = (unsigned char *)OPENSSL_malloc(length);
     if (data == NULL) {
-      i = ERR_R_MALLOC_FAILURE;
       goto err;
     }
     ret->flags |= ASN1_OBJECT_FLAG_DYNAMIC_DATA;
@@ -236,7 +234,6 @@
   *pp = p;
   return ret;
 err:
-  OPENSSL_PUT_ERROR(ASN1, i);
   if ((ret != NULL) && ((a == NULL) || (*a != ret))) {
     ASN1_OBJECT_free(ret);
   }
@@ -248,7 +245,6 @@
 
   ret = (ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   ret->length = 0;
diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c
index 73f828e..3b97b38 100644
--- a/crypto/asn1/asn1_lib.c
+++ b/crypto/asn1/asn1_lib.c
@@ -299,7 +299,6 @@
     }
 
     if (str->data == NULL) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       str->data = c;
       return 0;
     }
@@ -331,7 +330,6 @@
 
   ret = (ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   ret->length = 0;
diff --git a/crypto/asn1/asn_pack.c b/crypto/asn1/asn_pack.c
index 069cef0..c42cc05 100644
--- a/crypto/asn1/asn_pack.c
+++ b/crypto/asn1/asn_pack.c
@@ -72,7 +72,6 @@
   if (out == NULL || *out == NULL) {
     ret = ASN1_STRING_new();
     if (ret == NULL) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       OPENSSL_free(new_data);
       return NULL;
     }
diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c
index 39329b6..4f25fbb 100644
--- a/crypto/asn1/tasn_dec.c
+++ b/crypto/asn1/tasn_dec.c
@@ -590,7 +590,6 @@
     }
 
     if (!*val) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       goto err;
     }
 
@@ -607,7 +606,6 @@
       len -= p - q;
       if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
         ASN1_item_ex_free(&skfield, ASN1_ITEM_ptr(tt->item));
-        OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
         goto err;
       }
     }
@@ -872,7 +870,6 @@
       if (!*pval) {
         stmp = ASN1_STRING_type_new(utype);
         if (!stmp) {
-          OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
           goto err;
         }
         *pval = (ASN1_VALUE *)stmp;
@@ -881,7 +878,6 @@
         stmp->type = utype;
       }
       if (!ASN1_STRING_set(stmp, cont, len)) {
-        OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
         ASN1_STRING_free(stmp);
         *pval = NULL;
         goto err;
diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c
index e46968c..9d4d587 100644
--- a/crypto/asn1/tasn_enc.c
+++ b/crypto/asn1/tasn_enc.c
@@ -92,7 +92,6 @@
     }
     buf = OPENSSL_malloc(len);
     if (!buf) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       return -1;
     }
     p = buf;
@@ -461,7 +460,6 @@
   unsigned char *const buf = OPENSSL_malloc(skcontlen);
   DER_ENC *encoded = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*encoded));
   if (encoded == NULL || buf == NULL) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c
index 3727b9b..8a90b43 100644
--- a/crypto/asn1/tasn_new.c
+++ b/crypto/asn1/tasn_new.c
@@ -175,7 +175,6 @@
 memerr2:
   ASN1_item_ex_free(pval, it);
 memerr:
-  OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
   return 0;
 
 auxerr2:
@@ -235,7 +234,6 @@
     STACK_OF(ASN1_VALUE) *skval;
     skval = sk_ASN1_VALUE_new_null();
     if (!skval) {
-      OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
       ret = 0;
       goto done;
     }
diff --git a/crypto/bio/bio.c b/crypto/bio/bio.c
index 453e45a..610c733 100644
--- a/crypto/bio/bio.c
+++ b/crypto/bio/bio.c
@@ -72,7 +72,6 @@
 BIO *BIO_new(const BIO_METHOD *method) {
   BIO *ret = OPENSSL_malloc(sizeof(BIO));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(BIO, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -609,7 +608,6 @@
 
   *out = OPENSSL_malloc(len);
   if (*out == NULL) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   OPENSSL_memcpy(*out, header, header_len);
diff --git a/crypto/bio/pair.c b/crypto/bio/pair.c
index 8f47568..c4d09c1 100644
--- a/crypto/bio/pair.c
+++ b/crypto/bio/pair.c
@@ -317,7 +317,6 @@
     }
     b1->buf = OPENSSL_malloc(b1->size);
     if (b1->buf == NULL) {
-      OPENSSL_PUT_ERROR(BIO, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     b1->len = 0;
@@ -330,7 +329,6 @@
     }
     b2->buf = OPENSSL_malloc(b2->size);
     if (b2->buf == NULL) {
-      OPENSSL_PUT_ERROR(BIO, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     b2->len = 0;
diff --git a/crypto/bio/printf.c b/crypto/bio/printf.c
index 253546b..102256b 100644
--- a/crypto/bio/printf.c
+++ b/crypto/bio/printf.c
@@ -83,7 +83,6 @@
     out = OPENSSL_malloc(requested_len + 1);
     out_malloced = 1;
     if (out == NULL) {
-      OPENSSL_PUT_ERROR(BIO, ERR_R_MALLOC_FAILURE);
       return -1;
     }
     va_start(args, format);
diff --git a/crypto/bn_extra/convert.c b/crypto/bn_extra/convert.c
index 78fe102..29234ef 100644
--- a/crypto/bn_extra/convert.c
+++ b/crypto/bn_extra/convert.c
@@ -81,7 +81,6 @@
   char *buf = OPENSSL_malloc(1 /* leading '-' */ + 1 /* zero is non-empty */ +
                              width * BN_BYTES * 2 + 1 /* trailing NUL */);
   if (buf == NULL) {
-    OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -241,12 +240,12 @@
   CBB cbb;
   if (!CBB_init(&cbb, 16) ||
       !CBB_add_u8(&cbb, 0 /* trailing NUL */)) {
-    goto cbb_err;
+    goto err;
   }
 
   if (BN_is_zero(a)) {
     if (!CBB_add_u8(&cbb, '0')) {
-      goto cbb_err;
+      goto err;
     }
   } else {
     copy = BN_dup(a);
@@ -263,7 +262,7 @@
       const int add_leading_zeros = !BN_is_zero(copy);
       for (int i = 0; i < BN_DEC_NUM && (add_leading_zeros || word != 0); i++) {
         if (!CBB_add_u8(&cbb, '0' + word % 10)) {
-          goto cbb_err;
+          goto err;
         }
         word /= 10;
       }
@@ -273,13 +272,13 @@
 
   if (BN_is_negative(a) &&
       !CBB_add_u8(&cbb, '-')) {
-    goto cbb_err;
+    goto err;
   }
 
   uint8_t *data;
   size_t len;
   if (!CBB_finish(&cbb, &data, &len)) {
-    goto cbb_err;
+    goto err;
   }
 
   // Reverse the buffer.
@@ -292,8 +291,6 @@
   BN_free(copy);
   return (char *)data;
 
-cbb_err:
-  OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
 err:
   BN_free(copy);
   CBB_cleanup(&cbb);
@@ -427,7 +424,6 @@
   if (out == NULL) {
     out = BN_new();
     if (out == NULL) {
-      OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
       return NULL;
     }
     out_is_alloced = 1;
diff --git a/crypto/buf/buf.c b/crypto/buf/buf.c
index bd97dd3..57bf34d 100644
--- a/crypto/buf/buf.c
+++ b/crypto/buf/buf.c
@@ -69,7 +69,6 @@
 
   ret = OPENSSL_malloc(sizeof(BUF_MEM));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(BUF, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -93,21 +92,18 @@
 
   size_t n = cap + 3;
   if (n < cap) {
-    // overflow
-    OPENSSL_PUT_ERROR(BUF, ERR_R_MALLOC_FAILURE);
+    OPENSSL_PUT_ERROR(BUF, ERR_R_OVERFLOW);
     return 0;
   }
   n = n / 3;
   size_t alloc_size = n * 4;
   if (alloc_size / 4 != n) {
-    // overflow
-    OPENSSL_PUT_ERROR(BUF, ERR_R_MALLOC_FAILURE);
+    OPENSSL_PUT_ERROR(BUF, ERR_R_OVERFLOW);
     return 0;
   }
 
   char *new_buf = OPENSSL_realloc(buf->data, alloc_size);
   if (new_buf == NULL) {
-    OPENSSL_PUT_ERROR(BUF, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/bytestring/cbb.c b/crypto/bytestring/cbb.c
index 1692b4e..5280dc8 100644
--- a/crypto/bytestring/cbb.c
+++ b/crypto/bytestring/cbb.c
@@ -19,6 +19,7 @@
 #include <string.h>
 
 #include <openssl/mem.h>
+#include <openssl/err.h>
 
 #include "../internal.h"
 
@@ -77,11 +78,13 @@
   size_t newlen = base->len + len;
   if (newlen < base->len) {
     // Overflow
+    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
     goto err;
   }
 
   if (newlen > base->cap) {
     if (!base->can_resize) {
+      OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
       goto err;
     }
 
@@ -121,6 +124,7 @@
 
 int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len) {
   if (cbb->is_child) {
+    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
     return 0;
   }
 
@@ -191,6 +195,7 @@
     assert (child->pending_len_len == 1);
 
     if (len > 0xfffffffe) {
+      OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
       // Too large.
       goto err;
     } else if (len > 0xffffff) {
@@ -229,6 +234,7 @@
     len >>= 8;
   }
   if (len != 0) {
+    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
     goto err;
   }
 
@@ -634,6 +640,7 @@
   CBS_init(&cbs, CBB_data(cbb), CBB_len(cbb));
   while (CBS_len(&cbs) != 0) {
     if (!CBS_get_any_asn1_element(&cbs, NULL, NULL, NULL)) {
+      OPENSSL_PUT_ERROR(CRYPTO, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
       return 0;
     }
     num_children++;
diff --git a/crypto/conf/conf.c b/crypto/conf/conf.c
index 8874896..622c13e 100644
--- a/crypto/conf/conf.c
+++ b/crypto/conf/conf.c
@@ -132,7 +132,6 @@
 CONF_VALUE *CONF_VALUE_new(void) {
   CONF_VALUE *v = OPENSSL_malloc(sizeof(CONF_VALUE));
   if (!v) {
-    OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(v, 0, sizeof(CONF_VALUE));
@@ -340,7 +339,6 @@
         goto err;
       }
       if (!BUF_MEM_grow_clean(buf, newsize)) {
-        OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       while (*p) {
@@ -552,7 +550,6 @@
 
   section = OPENSSL_strdup(kDefaultSectionName);
   if (section == NULL) {
-    OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -687,7 +684,6 @@
       }
       v->name = OPENSSL_strdup(pname);
       if (v->name == NULL) {
-        OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       if (!str_copy(conf, psection, &(v->value), start)) {
@@ -706,7 +702,6 @@
         tv = sv;
       }
       if (add_string(conf, tv, v) == 0) {
-        OPENSSL_PUT_ERROR(CONF, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       v = NULL;
diff --git a/crypto/digest_extra/digest_extra.c b/crypto/digest_extra/digest_extra.c
index 8cbb28e..08ed671 100644
--- a/crypto/digest_extra/digest_extra.c
+++ b/crypto/digest_extra/digest_extra.c
@@ -200,7 +200,6 @@
   CBB algorithm, oid, null;
   if (!CBB_add_asn1(cbb, &algorithm, CBS_ASN1_SEQUENCE) ||
       !CBB_add_asn1(&algorithm, &oid, CBS_ASN1_OBJECT)) {
-    OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -209,7 +208,6 @@
   for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kMDOIDs); i++) {
     if (nid == kMDOIDs[i].nid) {
       if (!CBB_add_bytes(&oid, kMDOIDs[i].oid, kMDOIDs[i].oid_len)) {
-        OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE);
         return 0;
       }
       found = 1;
@@ -224,7 +222,6 @@
 
   if (!CBB_add_asn1(&algorithm, &null, CBS_ASN1_NULL) ||
       !CBB_flush(cbb)) {
-    OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/dsa/dsa.c b/crypto/dsa/dsa.c
index ecffdf7..4d9b1f0 100644
--- a/crypto/dsa/dsa.c
+++ b/crypto/dsa/dsa.c
@@ -90,7 +90,6 @@
 DSA *DSA_new(void) {
   DSA *dsa = OPENSSL_malloc(sizeof(DSA));
   if (dsa == NULL) {
-    OPENSSL_PUT_ERROR(DSA, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
diff --git a/crypto/ec_extra/ec_asn1.c b/crypto/ec_extra/ec_asn1.c
index ee75165..5c0dab1 100644
--- a/crypto/ec_extra/ec_asn1.c
+++ b/crypto/ec_extra/ec_asn1.c
@@ -504,7 +504,6 @@
   ret = *keyp;
   if (ret->pub_key == NULL &&
       (ret->pub_key = EC_POINT_new(ret->group)) == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   if (!EC_POINT_oct2point(ret->group, ret->pub_key, *inp, len, NULL)) {
diff --git a/crypto/evp/evp.c b/crypto/evp/evp.c
index f11ef9f..39e40fd 100644
--- a/crypto/evp/evp.c
+++ b/crypto/evp/evp.c
@@ -85,7 +85,6 @@
 
   ret = OPENSSL_malloc(sizeof(EVP_PKEY));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
diff --git a/crypto/evp/evp_ctx.c b/crypto/evp/evp_ctx.c
index 5f31ddb..771f13f 100644
--- a/crypto/evp/evp_ctx.c
+++ b/crypto/evp/evp_ctx.c
@@ -88,7 +88,6 @@
                                       const EVP_PKEY_METHOD *pmeth) {
   EVP_PKEY_CTX *ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
   if (!ret) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(ret, 0, sizeof(EVP_PKEY_CTX));
diff --git a/crypto/evp/p_ed25519.c b/crypto/evp/p_ed25519.c
index b3d8cc9..cd787a1 100644
--- a/crypto/evp/p_ed25519.c
+++ b/crypto/evp/p_ed25519.c
@@ -27,7 +27,6 @@
 static int pkey_ed25519_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
   ED25519_KEY *key = OPENSSL_malloc(sizeof(ED25519_KEY));
   if (key == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/evp/p_ed25519_asn1.c b/crypto/evp/p_ed25519_asn1.c
index 9f9251c..c3f8885 100644
--- a/crypto/evp/p_ed25519_asn1.c
+++ b/crypto/evp/p_ed25519_asn1.c
@@ -36,7 +36,6 @@
 
   ED25519_KEY *key = OPENSSL_malloc(sizeof(ED25519_KEY));
   if (key == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -59,7 +58,6 @@
 
   ED25519_KEY *key = OPENSSL_malloc(sizeof(ED25519_KEY));
   if (key == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/evp/p_hkdf.c b/crypto/evp/p_hkdf.c
index 05158e2..0d7ede8 100644
--- a/crypto/evp/p_hkdf.c
+++ b/crypto/evp/p_hkdf.c
@@ -37,13 +37,11 @@
 static int pkey_hkdf_init(EVP_PKEY_CTX *ctx) {
   HKDF_PKEY_CTX *hctx = OPENSSL_malloc(sizeof(HKDF_PKEY_CTX));
   if (hctx == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
   OPENSSL_memset(hctx, 0, sizeof(HKDF_PKEY_CTX));
   if (!CBB_init(&hctx->info, 0)) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     OPENSSL_free(hctx);
     return 0;
   }
@@ -65,7 +63,6 @@
   if (hctx_src->key_len != 0) {
     hctx_dst->key = OPENSSL_memdup(hctx_src->key, hctx_src->key_len);
     if (hctx_dst->key == NULL) {
-      OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     hctx_dst->key_len = hctx_src->key_len;
@@ -74,7 +71,6 @@
   if (hctx_src->salt_len != 0) {
     hctx_dst->salt = OPENSSL_memdup(hctx_src->salt, hctx_src->salt_len);
     if (hctx_dst->salt == NULL) {
-      OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     hctx_dst->salt_len = hctx_src->salt_len;
@@ -82,7 +78,6 @@
 
   if (!CBB_add_bytes(&hctx_dst->info, CBB_data(&hctx_src->info),
                      CBB_len(&hctx_src->info))) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -159,7 +154,6 @@
     case EVP_PKEY_CTRL_HKDF_KEY: {
       const CBS *key = p2;
       if (!CBS_stow(key, &hctx->key, &hctx->key_len)) {
-        OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
         return 0;
       }
       return 1;
@@ -167,7 +161,6 @@
     case EVP_PKEY_CTRL_HKDF_SALT: {
       const CBS *salt = p2;
       if (!CBS_stow(salt, &hctx->salt, &hctx->salt_len)) {
-        OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
         return 0;
       }
       return 1;
@@ -177,7 +170,6 @@
       // |EVP_PKEY_CTX_add1_hkdf_info| appends to the info string, rather than
       // replacing it.
       if (!CBB_add_bytes(&hctx->info, CBS_data(info), CBS_len(info))) {
-        OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
         return 0;
       }
       return 1;
diff --git a/crypto/evp/p_x25519.c b/crypto/evp/p_x25519.c
index ed7df39..75ef6e1 100644
--- a/crypto/evp/p_x25519.c
+++ b/crypto/evp/p_x25519.c
@@ -27,7 +27,6 @@
 static int pkey_x25519_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) {
   X25519_KEY *key = OPENSSL_malloc(sizeof(X25519_KEY));
   if (key == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/evp/p_x25519_asn1.c b/crypto/evp/p_x25519_asn1.c
index e36b41e..3573f24 100644
--- a/crypto/evp/p_x25519_asn1.c
+++ b/crypto/evp/p_x25519_asn1.c
@@ -36,7 +36,6 @@
 
   X25519_KEY *key = OPENSSL_malloc(sizeof(X25519_KEY));
   if (key == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -57,7 +56,6 @@
 
   X25519_KEY *key = OPENSSL_malloc(sizeof(X25519_KEY));
   if (key == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/evp/print.c b/crypto/evp/print.c
index 11fad3c..ed0fb0e 100644
--- a/crypto/evp/print.c
+++ b/crypto/evp/print.c
@@ -117,7 +117,6 @@
   size_t len = BN_num_bytes(num);
   uint8_t *buf = OPENSSL_malloc(len + 1);
   if (buf == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/evp/scrypt.c b/crypto/evp/scrypt.c
index 14a5e02..8212cd1 100644
--- a/crypto/evp/scrypt.c
+++ b/crypto/evp/scrypt.c
@@ -177,7 +177,6 @@
   size_t V_blocks = N * 2 * r;
   block_t *B = OPENSSL_malloc((B_blocks + T_blocks + V_blocks) * sizeof(block_t));
   if (B == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/ex_data.c b/crypto/ex_data.c
index 532a3ad..867ced3 100644
--- a/crypto/ex_data.c
+++ b/crypto/ex_data.c
@@ -137,7 +137,6 @@
 
   funcs = OPENSSL_malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
   if (funcs == NULL) {
-    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -152,7 +151,6 @@
   }
 
   if (ex_data_class->meth == NULL) {
-    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -164,7 +162,6 @@
   }
 
   if (!sk_CRYPTO_EX_DATA_FUNCS_push(ex_data_class->meth, funcs)) {
-    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   funcs = NULL;  // |sk_CRYPTO_EX_DATA_FUNCS_push| takes ownership.
@@ -190,7 +187,6 @@
   if (ad->sk == NULL) {
     ad->sk = sk_void_new_null();
     if (ad->sk == NULL) {
-      OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
       return 0;
     }
   }
@@ -198,7 +194,6 @@
   // Add NULL values until the stack is long enough.
   for (size_t i = sk_void_num(ad->sk); i <= (size_t)index; i++) {
     if (!sk_void_push(ad->sk, NULL)) {
-      OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
       return 0;
     }
   }
@@ -235,7 +230,6 @@
   CRYPTO_STATIC_MUTEX_unlock_read(&ex_data_class->lock);
 
   if (n > 0 && *out == NULL) {
-    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/fipsmodule/bn/bn.c b/crypto/fipsmodule/bn/bn.c
index 93fae56..d7d8626 100644
--- a/crypto/fipsmodule/bn/bn.c
+++ b/crypto/fipsmodule/bn/bn.c
@@ -76,7 +76,6 @@
   BIGNUM *bn = OPENSSL_malloc(sizeof(BIGNUM));
 
   if (bn == NULL) {
-    OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -364,7 +363,6 @@
 
   a = OPENSSL_malloc(sizeof(BN_ULONG) * words);
   if (a == NULL) {
-    OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/fipsmodule/bn/ctx.c b/crypto/fipsmodule/bn/ctx.c
index f8c7ebf..0073161 100644
--- a/crypto/fipsmodule/bn/ctx.c
+++ b/crypto/fipsmodule/bn/ctx.c
@@ -108,7 +108,6 @@
 BN_CTX *BN_CTX_new(void) {
   BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));
   if (!ret) {
-    OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -162,7 +161,6 @@
   if (ctx->bignums == NULL) {
     ctx->bignums = sk_BIGNUM_new_null();
     if (ctx->bignums == NULL) {
-      OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
       ctx->error = 1;
       return NULL;
     }
diff --git a/crypto/fipsmodule/bn/gcd.c b/crypto/fipsmodule/bn/gcd.c
index bd0fa6f..e8cc764 100644
--- a/crypto/fipsmodule/bn/gcd.c
+++ b/crypto/fipsmodule/bn/gcd.c
@@ -286,7 +286,6 @@
   if (out == NULL) {
     new_out = BN_new();
     if (new_out == NULL) {
-      OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
       return NULL;
     }
     out = new_out;
diff --git a/crypto/fipsmodule/bn/prime.c b/crypto/fipsmodule/bn/prime.c
index 0578558..2d2ab69 100644
--- a/crypto/fipsmodule/bn/prime.c
+++ b/crypto/fipsmodule/bn/prime.c
@@ -362,7 +362,6 @@
 BN_GENCB *BN_GENCB_new(void) {
   BN_GENCB *callback = OPENSSL_malloc(sizeof(BN_GENCB));
   if (callback == NULL) {
-    OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(callback, 0, sizeof(BN_GENCB));
diff --git a/crypto/fipsmodule/bn/sqrt.c b/crypto/fipsmodule/bn/sqrt.c
index 9180d54..f976753 100644
--- a/crypto/fipsmodule/bn/sqrt.c
+++ b/crypto/fipsmodule/bn/sqrt.c
@@ -445,7 +445,6 @@
   last_delta = BN_CTX_get(ctx);
   delta = BN_CTX_get(ctx);
   if (estimate == NULL || tmp == NULL || last_delta == NULL || delta == NULL) {
-    OPENSSL_PUT_ERROR(BN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/fipsmodule/cipher/cipher.c b/crypto/fipsmodule/cipher/cipher.c
index ee45578..18b5e0a 100644
--- a/crypto/fipsmodule/cipher/cipher.c
+++ b/crypto/fipsmodule/cipher/cipher.c
@@ -116,7 +116,6 @@
     out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
     if (!out->cipher_data) {
       out->cipher = NULL;
-      OPENSSL_PUT_ERROR(CIPHER, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     OPENSSL_memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
@@ -165,7 +164,6 @@
       ctx->cipher_data = OPENSSL_malloc(ctx->cipher->ctx_size);
       if (!ctx->cipher_data) {
         ctx->cipher = NULL;
-        OPENSSL_PUT_ERROR(CIPHER, ERR_R_MALLOC_FAILURE);
         return 0;
       }
     } else {
diff --git a/crypto/fipsmodule/dh/dh.c b/crypto/fipsmodule/dh/dh.c
index 11dbfc2..8343511 100644
--- a/crypto/fipsmodule/dh/dh.c
+++ b/crypto/fipsmodule/dh/dh.c
@@ -75,7 +75,6 @@
 DH *DH_new(void) {
   DH *dh = OPENSSL_malloc(sizeof(DH));
   if (dh == NULL) {
-    OPENSSL_PUT_ERROR(DH, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
diff --git a/crypto/fipsmodule/digest/digest.c b/crypto/fipsmodule/digest/digest.c
index cb723d6..f499c46 100644
--- a/crypto/fipsmodule/digest/digest.c
+++ b/crypto/fipsmodule/digest/digest.c
@@ -144,7 +144,6 @@
   if (in->pctx) {
     pctx = in->pctx_ops->dup(in->pctx);
     if (!pctx) {
-      OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE);
       return 0;
     }
   }
@@ -158,7 +157,6 @@
         if (pctx) {
           in->pctx_ops->free(pctx);
         }
-        OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE);
         return 0;
       }
     } else {
@@ -207,7 +205,6 @@
     assert(type->ctx_size != 0);
     uint8_t *md_data = OPENSSL_malloc(type->ctx_size);
     if (md_data == NULL) {
-      OPENSSL_PUT_ERROR(DIGEST, ERR_R_MALLOC_FAILURE);
       return 0;
     }
 
diff --git a/crypto/fipsmodule/ec/ec.c b/crypto/fipsmodule/ec/ec.c
index debb965..61ecc1f 100644
--- a/crypto/fipsmodule/ec/ec.c
+++ b/crypto/fipsmodule/ec/ec.c
@@ -285,7 +285,6 @@
 
   ret = OPENSSL_malloc(sizeof(EC_GROUP));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(ret, 0, sizeof(EC_GROUP));
@@ -447,7 +446,6 @@
 
   BN_CTX *ctx = BN_CTX_new();
   if (ctx == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -686,7 +684,6 @@
 
   EC_POINT *ret = OPENSSL_malloc(sizeof *ret);
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
diff --git a/crypto/fipsmodule/ec/ec_key.c b/crypto/fipsmodule/ec/ec_key.c
index 31a097e..f391a61 100644
--- a/crypto/fipsmodule/ec/ec_key.c
+++ b/crypto/fipsmodule/ec/ec_key.c
@@ -88,7 +88,6 @@
 static EC_WRAPPED_SCALAR *ec_wrapped_scalar_new(const EC_GROUP *group) {
   EC_WRAPPED_SCALAR *wrapped = OPENSSL_malloc(sizeof(EC_WRAPPED_SCALAR));
   if (wrapped == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -109,7 +108,6 @@
 EC_KEY *EC_KEY_new_method(const ENGINE *engine) {
   EC_KEY *ret = OPENSSL_malloc(sizeof(EC_KEY));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -142,7 +140,6 @@
 EC_KEY *EC_KEY_new_by_curve_name(int nid) {
   EC_KEY *ret = EC_KEY_new();
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   ret->group = EC_GROUP_new_by_curve_name(nid);
@@ -467,7 +464,6 @@
 
   uint8_t *buf = OPENSSL_malloc(len);
   if (buf == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/fipsmodule/ec/oct.c b/crypto/fipsmodule/ec/oct.c
index dd2e007..3f0c0d6 100644
--- a/crypto/fipsmodule/ec/oct.c
+++ b/crypto/fipsmodule/ec/oct.c
@@ -241,7 +241,6 @@
   }
   uint8_t *buf = OPENSSL_malloc(len);
   if (buf == NULL) {
-    OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   len = EC_POINT_point2oct(group, point, form, buf, len, ctx);
diff --git a/crypto/fipsmodule/ec/wnaf.c b/crypto/fipsmodule/ec/wnaf.c
index 65cc894..ce0d4b8 100644
--- a/crypto/fipsmodule/ec/wnaf.c
+++ b/crypto/fipsmodule/ec/wnaf.c
@@ -205,7 +205,6 @@
     wNAF_alloc = OPENSSL_malloc(num * sizeof(wNAF_alloc[0]));
     precomp_alloc = OPENSSL_malloc(num * sizeof(precomp_alloc[0]));
     if (wNAF_alloc == NULL || precomp_alloc == NULL) {
-      OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     wNAF = wNAF_alloc;
diff --git a/crypto/fipsmodule/rsa/blinding.c b/crypto/fipsmodule/rsa/blinding.c
index 29477bd..c4cfcc2 100644
--- a/crypto/fipsmodule/rsa/blinding.c
+++ b/crypto/fipsmodule/rsa/blinding.c
@@ -132,7 +132,6 @@
 BN_BLINDING *BN_BLINDING_new(void) {
   BN_BLINDING *ret = OPENSSL_malloc(sizeof(BN_BLINDING));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(ret, 0, sizeof(BN_BLINDING));
diff --git a/crypto/fipsmodule/rsa/padding.c b/crypto/fipsmodule/rsa/padding.c
index 17d4c62..85f7835 100644
--- a/crypto/fipsmodule/rsa/padding.c
+++ b/crypto/fipsmodule/rsa/padding.c
@@ -358,7 +358,6 @@
 
   dbmask = OPENSSL_malloc(emlen - mdlen);
   if (dbmask == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     goto out;
   }
 
@@ -413,7 +412,6 @@
   FIPS_service_indicator_lock_state();
   db = OPENSSL_malloc(dblen);
   if (db == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -543,7 +541,6 @@
   const uint8_t *H = EM + maskedDBLen;
   DB = OPENSSL_malloc(maskedDBLen);
   if (!DB) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   if (!PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash)) {
@@ -653,7 +650,6 @@
   if (sLen > 0) {
     salt = OPENSSL_malloc(sLen);
     if (!salt) {
-      OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     if (!RAND_bytes(salt, sLen)) {
diff --git a/crypto/fipsmodule/rsa/rsa.c b/crypto/fipsmodule/rsa/rsa.c
index bbac05f..2139275 100644
--- a/crypto/fipsmodule/rsa/rsa.c
+++ b/crypto/fipsmodule/rsa/rsa.c
@@ -88,7 +88,6 @@
 RSA *RSA_new_method(const ENGINE *engine) {
   RSA *rsa = OPENSSL_malloc(sizeof(RSA));
   if (rsa == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -530,7 +529,6 @@
 
     uint8_t *signed_msg = OPENSSL_malloc(signed_msg_len);
     if (!signed_msg) {
-      OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
       return 0;
     }
 
@@ -610,7 +608,6 @@
   size_t padded_len = RSA_size(rsa);
   uint8_t *padded = OPENSSL_malloc(padded_len);
   if (padded == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -644,7 +641,6 @@
 
   buf = OPENSSL_malloc(rsa_size);
   if (!buf) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -691,7 +687,6 @@
   size_t em_len = RSA_size(rsa);
   uint8_t *em = OPENSSL_malloc(em_len);
   if (em == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -772,7 +767,6 @@
 
   BN_CTX *ctx = BN_CTX_new();
   if (ctx == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -900,7 +894,6 @@
 
   BN_CTX *ctx = BN_CTX_new();
   if (ctx == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -947,7 +940,6 @@
   unsigned sig_len = RSA_size(key);
   uint8_t *sig = OPENSSL_malloc(sig_len);
   if (sig == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/fipsmodule/rsa/rsa_impl.c b/crypto/fipsmodule/rsa/rsa_impl.c
index df465f2..4500b1a 100644
--- a/crypto/fipsmodule/rsa/rsa_impl.c
+++ b/crypto/fipsmodule/rsa/rsa_impl.c
@@ -295,7 +295,6 @@
   result = BN_CTX_get(ctx);
   buf = OPENSSL_malloc(rsa_size);
   if (!f || !result || !buf) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -498,7 +497,6 @@
 
   buf = OPENSSL_malloc(rsa_size);
   if (buf == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -551,7 +549,6 @@
     // Allocate a temporary buffer to hold the padded plaintext.
     buf = OPENSSL_malloc(rsa_size);
     if (buf == NULL) {
-      OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
       goto err;
     }
   }
@@ -633,7 +630,6 @@
   f = BN_CTX_get(ctx);
   result = BN_CTX_get(ctx);
   if (f == NULL || result == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -643,7 +639,6 @@
     // Allocate a temporary buffer to hold the padded plaintext.
     buf = OPENSSL_malloc(rsa_size);
     if (buf == NULL) {
-      OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
       goto err;
     }
   }
@@ -725,7 +720,6 @@
   result = BN_CTX_get(ctx);
 
   if (f == NULL || result == NULL) {
-    OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/fipsmodule/service_indicator/service_indicator.c b/crypto/fipsmodule/service_indicator/service_indicator.c
index febe534..dd38bd7 100644
--- a/crypto/fipsmodule/service_indicator/service_indicator.c
+++ b/crypto/fipsmodule/service_indicator/service_indicator.c
@@ -51,7 +51,6 @@
   if (indicator == NULL) {
     indicator = OPENSSL_malloc(sizeof(struct fips_service_indicator_state));
     if (indicator == NULL) {
-      OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
       return NULL;
     }
 
diff --git a/crypto/hpke/hpke.c b/crypto/hpke/hpke.c
index faea2ee..3dfdb29 100644
--- a/crypto/hpke/hpke.c
+++ b/crypto/hpke/hpke.c
@@ -250,7 +250,6 @@
 EVP_HPKE_KEY *EVP_HPKE_KEY_new(void) {
   EVP_HPKE_KEY *key = OPENSSL_malloc(sizeof(EVP_HPKE_KEY));
   if (key == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   EVP_HPKE_KEY_zero(key);
@@ -465,7 +464,6 @@
 EVP_HPKE_CTX *EVP_HPKE_CTX_new(void) {
   EVP_HPKE_CTX *ctx = OPENSSL_malloc(sizeof(EVP_HPKE_CTX));
   if (ctx == NULL) {
-    OPENSSL_PUT_ERROR(EVP, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   EVP_HPKE_CTX_zero(ctx);
diff --git a/crypto/internal.h b/crypto/internal.h
index f12871f..a4cd929 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -1299,7 +1299,7 @@
 extern uint8_t BORINGSSL_function_hit[7];
 #endif  // BORINGSSL_DISPATCH_TEST
 
-// OPENSSL_vasprintf_internal is just like |vasprintf(3)|. if |system_malloc| is
+// OPENSSL_vasprintf_internal is just like |vasprintf(3)|. If |system_malloc| is
 // 0, memory will be allocated with |OPENSSL_malloc| and must be freed with
 // |OPENSSL_free|. Otherwise the system |malloc| function is used and the memory
 // must be freed with the system |free| function.
diff --git a/crypto/mem.c b/crypto/mem.c
index f75e89e..4905caf 100644
--- a/crypto/mem.c
+++ b/crypto/mem.c
@@ -227,13 +227,17 @@
 
 void *OPENSSL_malloc(size_t size) {
   if (should_fail_allocation()) {
-    return NULL;
+    goto err;
   }
 
   if (OPENSSL_memory_alloc != NULL) {
     assert(OPENSSL_memory_free != NULL);
     assert(OPENSSL_memory_get_size != NULL);
-    return OPENSSL_memory_alloc(size);
+    void *ptr = OPENSSL_memory_alloc(size);
+    if (ptr == NULL && size != 0) {
+      goto err;
+    }
+    return ptr;
   }
 
   if (size + OPENSSL_MALLOC_PREFIX < size) {
@@ -245,18 +249,23 @@
     // rare code path.
     uint8_t unused = *(volatile uint8_t *)kBoringSSLBinaryTag;
     (void) unused;
-    return NULL;
+    goto err;
   }
 
   void *ptr = malloc(size + OPENSSL_MALLOC_PREFIX);
   if (ptr == NULL) {
-    return NULL;
+    goto err;
   }
 
   *(size_t *)ptr = size;
 
   __asan_poison_memory_region(ptr, OPENSSL_MALLOC_PREFIX);
   return ((uint8_t *)ptr) + OPENSSL_MALLOC_PREFIX;
+
+ err:
+  // This only works because ERR does not call OPENSSL_malloc.
+  OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
+  return NULL;
 }
 
 void OPENSSL_free(void *orig_ptr) {
@@ -289,10 +298,6 @@
 }
 
 void *OPENSSL_realloc(void *orig_ptr, size_t new_size) {
-  if (should_fail_allocation()) {
-    return NULL;
-  }
-
   if (orig_ptr == NULL) {
     return OPENSSL_malloc(new_size);
   }
@@ -505,24 +510,21 @@
   va_copy(args_copy, args);
   int ret = vsnprintf(candidate, candidate_len, format, args_copy);
   va_end(args_copy);
-  if (ret == INT_MAX || ret < 0) {
-    // Failed, or size not int representable.
+  if (ret < 0) {
     goto err;
   }
   if ((size_t)ret >= candidate_len) {
     // Too big to fit in allocation.
     char *tmp;
 
-    candidate_len = ret + 1;
+    candidate_len = (size_t)ret + 1;
     if ((tmp = reallocate(candidate, candidate_len)) == NULL) {
       goto err;
     }
     candidate = tmp;
-    va_copy(args_copy, args);
-    ret = vsnprintf(candidate, candidate_len, format, args_copy);
-    va_end(args_copy);
+    ret = vsnprintf(candidate, candidate_len, format, args);
   }
-  // At this point this can't happen unless vsnprintf is insane.
+  // At this point this should not happen unless vsnprintf is insane.
   if (ret < 0 || (size_t)ret >= candidate_len) {
     goto err;
   }
@@ -559,7 +561,6 @@
   }
   char *ret = OPENSSL_malloc(alloc_size);
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -598,7 +599,6 @@
 
   void *ret = OPENSSL_malloc(size);
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(CRYPTO, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
diff --git a/crypto/obj/obj.c b/crypto/obj/obj.c
index c4e1aee..1ce9d54 100644
--- a/crypto/obj/obj.c
+++ b/crypto/obj/obj.c
@@ -155,7 +155,6 @@
   return r;
 
 err:
-  OPENSSL_PUT_ERROR(OBJ, ERR_R_MALLOC_FAILURE);
   OPENSSL_free(ln);
   OPENSSL_free(sn);
   OPENSSL_free(data);
diff --git a/crypto/pem/pem_info.c b/crypto/pem/pem_info.c
index 80c06b8..c097013 100644
--- a/crypto/pem/pem_info.c
+++ b/crypto/pem/pem_info.c
@@ -139,7 +139,6 @@
   if (sk == NULL) {
     ret = sk_X509_INFO_new_null();
     if (ret == NULL) {
-      OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
       return NULL;
     }
   } else {
diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c
index fc1144e..28ed438 100644
--- a/crypto/pem/pem_lib.c
+++ b/crypto/pem/pem_lib.c
@@ -298,7 +298,6 @@
   // actually it needs the cipher block size extra...
   data = (unsigned char *)OPENSSL_malloc((unsigned int)dsize + 20);
   if (data == NULL) {
-    OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   p = data;
@@ -552,7 +551,6 @@
 
   buf = OPENSSL_malloc(PEM_BUFSIZE * 8);
   if (buf == NULL) {
-    reason = ERR_R_MALLOC_FAILURE;
     goto err;
   }
 
@@ -615,7 +613,6 @@
     BUF_MEM_free(nameB);
     BUF_MEM_free(headerB);
     BUF_MEM_free(dataB);
-    OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -641,7 +638,6 @@
         continue;
       }
       if (!BUF_MEM_grow(nameB, i + 9)) {
-        OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       OPENSSL_memcpy(nameB->data, &(buf[11]), i - 6);
@@ -651,7 +647,6 @@
   }
   hl = 0;
   if (!BUF_MEM_grow(headerB, 256)) {
-    OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   headerB->data[0] = '\0';
@@ -671,7 +666,6 @@
       break;
     }
     if (!BUF_MEM_grow(headerB, hl + i + 9)) {
-      OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     if (strncmp(buf, "-----END ", 9) == 0) {
@@ -685,7 +679,6 @@
 
   bl = 0;
   if (!BUF_MEM_grow(dataB, 1024)) {
-    OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   dataB->data[0] = '\0';
@@ -712,7 +705,6 @@
         break;
       }
       if (!BUF_MEM_grow_clean(dataB, i + bl + 9)) {
-        OPENSSL_PUT_ERROR(PEM, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       OPENSSL_memcpy(&(dataB->data[bl]), buf, i);
diff --git a/crypto/pkcs7/pkcs7_x509.c b/crypto/pkcs7/pkcs7_x509.c
index 773c592..fd71bd7 100644
--- a/crypto/pkcs7/pkcs7_x509.c
+++ b/crypto/pkcs7/pkcs7_x509.c
@@ -328,7 +328,6 @@
   if (*out == NULL) {
     *out = OPENSSL_malloc(p7->ber_len);
     if (*out == NULL) {
-      OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
       return -1;
     }
     OPENSSL_memcpy(*out, p7->ber_bytes, p7->ber_len);
diff --git a/crypto/pkcs8/pkcs8.c b/crypto/pkcs8/pkcs8.c
index 84b7b12..6dd111b 100644
--- a/crypto/pkcs8/pkcs8.c
+++ b/crypto/pkcs8/pkcs8.c
@@ -76,7 +76,6 @@
                                   size_t *out_len) {
   CBB cbb;
   if (!CBB_init(&cbb, in_len * 2)) {
-    OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -162,7 +161,6 @@
 
   I = OPENSSL_malloc(I_len);
   if (I_len != 0 && I == NULL) {
-    OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -390,7 +388,6 @@
 
   buf = OPENSSL_malloc(in_len);
   if (buf == NULL) {
-    OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/pkcs8/pkcs8_x509.c b/crypto/pkcs8/pkcs8_x509.c
index de50567..83d34e6 100644
--- a/crypto/pkcs8/pkcs8_x509.c
+++ b/crypto/pkcs8/pkcs8_x509.c
@@ -334,7 +334,6 @@
       // Convert the friendly name to UTF-8.
       CBB cbb;
       if (!CBB_init(&cbb, CBS_len(&value))) {
-        OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       while (CBS_len(&value) != 0) {
@@ -347,7 +346,6 @@
         }
       }
       if (!CBB_finish(&cbb, out_friendly_name, out_friendly_name_len)) {
-        OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
         CBB_cleanup(&cbb);
         goto err;
       }
@@ -844,7 +842,6 @@
   if (*out == NULL) {
     *out = OPENSSL_malloc(p12->ber_len);
     if (*out == NULL) {
-      OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
       return -1;
     }
     OPENSSL_memcpy(*out, p12->ber_bytes, p12->ber_len);
@@ -883,7 +880,6 @@
   if (!ca_certs) {
     ca_certs = sk_X509_new_null();
     if (ca_certs == NULL) {
-      OPENSSL_PUT_ERROR(PKCS8, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     ca_certs_alloced = 1;
diff --git a/crypto/trust_token/pmbtoken.c b/crypto/trust_token/pmbtoken.c
index 7a95a7d..2e25cf5 100644
--- a/crypto/trust_token/pmbtoken.c
+++ b/crypto/trust_token/pmbtoken.c
@@ -332,7 +332,6 @@
   const EC_GROUP *group = method->group;
   STACK_OF(TRUST_TOKEN_PRETOKEN) *pretokens = sk_TRUST_TOKEN_PRETOKEN_new_null();
   if (pretokens == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -341,7 +340,6 @@
     TRUST_TOKEN_PRETOKEN *pretoken = OPENSSL_malloc(sizeof(TRUST_TOKEN_PRETOKEN));
     if (pretoken == NULL ||
         !sk_TRUST_TOKEN_PRETOKEN_push(pretokens, pretoken)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       TRUST_TOKEN_PRETOKEN_free(pretoken);
       goto err;
     }
@@ -360,7 +358,6 @@
     // We sample |pretoken->r| in Montgomery form to simplify inverting.
     if (!ec_random_nonzero_scalar(group, &pretoken->r,
                                   kDefaultAdditionalData)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       goto err;
     }
 
@@ -395,7 +392,6 @@
   uint8_t *buf;
   size_t scalar_len = BN_num_bytes(&group->order);
   if (!CBB_add_space(out, &buf, scalar_len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   ec_scalar_to_bytes(group, buf, &scalar_len, scalar);
@@ -435,7 +431,6 @@
       !point_to_cbb(&cbb, method->group, K1) ||
       !CBB_finish(&cbb, &buf, &len) ||
       !method->hash_c(method->group, out, buf, len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -473,7 +468,6 @@
       !point_to_cbb(&cbb, method->group, K11) ||
       !CBB_finish(&cbb, &buf, &len) ||
       !method->hash_c(method->group, out, buf, len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -505,7 +499,6 @@
       !CBB_add_u16(&cbb, (uint16_t)index) ||
       !CBB_finish(&cbb, &buf, &len) ||
       !method->hash_c(method->group, out, buf, len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -640,7 +633,6 @@
   if (!scalar_to_cbb(cbb, group, &cs) ||
       !scalar_to_cbb(cbb, group, &us) ||
       !scalar_to_cbb(cbb, group, &vs)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -676,7 +668,6 @@
       !scalar_to_cbb(cbb, group, &u1) ||
       !scalar_to_cbb(cbb, group, &v0) ||
       !scalar_to_cbb(cbb, group, &v1)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -835,7 +826,6 @@
       !point_to_cbb(&batch_cbb, method->group, &key->pubs) ||
       !point_to_cbb(&batch_cbb, method->group, &key->pub0) ||
       !point_to_cbb(&batch_cbb, method->group, &key->pub1)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -876,7 +866,6 @@
         !point_to_cbb(&batch_cbb, group, &affines[0]) ||
         !point_to_cbb(&batch_cbb, group, &affines[1]) ||
         !point_to_cbb(&batch_cbb, group, &affines[2])) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     Tps[i] = Tp;
@@ -958,7 +947,6 @@
   int ok = 0;
   STACK_OF(TRUST_TOKEN) *ret = sk_TRUST_TOKEN_new_null();
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -983,7 +971,6 @@
       !point_to_cbb(&batch_cbb, method->group, &key->pubs) ||
       !point_to_cbb(&batch_cbb, method->group, &key->pub0) ||
       !point_to_cbb(&batch_cbb, method->group, &key->pub1)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -1014,7 +1001,6 @@
         !point_to_cbb(&batch_cbb, group, &Sp_affine) ||
         !point_to_cbb(&batch_cbb, group, &Wp_affine) ||
         !point_to_cbb(&batch_cbb, group, &Wsp_affine)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       goto err;
     }
 
@@ -1052,7 +1038,6 @@
     CBB_cleanup(&token_cbb);
     if (token == NULL ||
         !sk_TRUST_TOKEN_push(ret, token)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       TRUST_TOKEN_free(token);
       goto err;
     }
@@ -1202,7 +1187,6 @@
       !CBB_finish(&cbb, &buf, &len) ||
       !ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
           group, out, kHashSLabel, sizeof(kHashSLabel), buf, len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -1376,7 +1360,6 @@
       !CBB_finish(&cbb, &buf, &len) ||
       !ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
           group, out, kHashSLabel, sizeof(kHashSLabel), buf, len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/trust_token/trust_token.c b/crypto/trust_token/trust_token.c
index 51b40ad..7cccf1a 100644
--- a/crypto/trust_token/trust_token.c
+++ b/crypto/trust_token/trust_token.c
@@ -85,13 +85,11 @@
 TRUST_TOKEN *TRUST_TOKEN_new(const uint8_t *data, size_t len) {
   TRUST_TOKEN *ret = OPENSSL_malloc(sizeof(TRUST_TOKEN));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(ret, 0, sizeof(TRUST_TOKEN));
   ret->data = OPENSSL_memdup(data, len);
   if (len != 0 && ret->data == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     OPENSSL_free(ret);
     return NULL;
   }
@@ -174,7 +172,6 @@
 
   TRUST_TOKEN_CLIENT *ret = OPENSSL_malloc(sizeof(TRUST_TOKEN_CLIENT));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(ret, 0, sizeof(TRUST_TOKEN_CLIENT));
@@ -238,7 +235,6 @@
   STACK_OF(TRUST_TOKEN_PRETOKEN) *pretokens = NULL;
   if (!CBB_init(&request, 0) ||
       !CBB_add_u16(&request, count)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -249,7 +245,6 @@
   }
 
   if (!CBB_finish(&request, out, out_len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -345,7 +340,6 @@
       !CBB_add_bytes(&inner, data, data_len) ||
       (ctx->method->has_srr && !CBB_add_u64(&request, time)) ||
       !CBB_finish(&request, out, out_len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     CBB_cleanup(&request);
     return 0;
   }
@@ -361,7 +355,6 @@
   CBS_init(&in, response, response_len);
   if (!ctx->method->has_srr) {
     if (!CBS_stow(&in, out_rr, out_rr_len)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       return 0;
     }
 
@@ -398,7 +391,6 @@
   size_t srr_len, sig_len;
   if (!CBS_stow(&srr, &srr_buf, &srr_len) ||
       !CBS_stow(&sig, &sig_buf, &sig_len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     OPENSSL_free(srr_buf);
     OPENSSL_free(sig_buf);
     return 0;
@@ -421,7 +413,6 @@
 
   TRUST_TOKEN_ISSUER *ret = OPENSSL_malloc(sizeof(TRUST_TOKEN_ISSUER));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(ret, 0, sizeof(TRUST_TOKEN_ISSUER));
@@ -479,7 +470,6 @@
   ctx->metadata_key_len = 0;
   ctx->metadata_key = OPENSSL_memdup(key, len);
   if (ctx->metadata_key == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   ctx->metadata_key_len = len;
@@ -531,7 +521,6 @@
   if (!CBB_init(&response, 0) ||
       !CBB_add_u16(&response, num_to_issue) ||
       !CBB_add_u32(&response, public_metadata)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -546,7 +535,6 @@
   }
 
   if (!CBB_finish(&response, out, out_len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -601,13 +589,11 @@
   uint8_t *client_data_buf = NULL;
   size_t client_data_len = 0;
   if (!CBS_stow(&client_data, &client_data_buf, &client_data_len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
   TRUST_TOKEN *token = TRUST_TOKEN_new(nonce, TRUST_TOKEN_NONCE_SIZE);
   if (token == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   *out_public = public_metadata;
diff --git a/crypto/trust_token/voprf.c b/crypto/trust_token/voprf.c
index da29c85..adf02a7 100644
--- a/crypto/trust_token/voprf.c
+++ b/crypto/trust_token/voprf.c
@@ -91,7 +91,6 @@
   uint8_t *buf;
   size_t scalar_len = BN_num_bytes(&group->order);
   if (!CBB_add_space(out, &buf, scalar_len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   ec_scalar_to_bytes(group, buf, &scalar_len, scalar);
@@ -212,7 +211,6 @@
   STACK_OF(TRUST_TOKEN_PRETOKEN) *pretokens =
       sk_TRUST_TOKEN_PRETOKEN_new_null();
   if (pretokens == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -222,7 +220,6 @@
         OPENSSL_malloc(sizeof(TRUST_TOKEN_PRETOKEN));
     if (pretoken == NULL ||
         !sk_TRUST_TOKEN_PRETOKEN_push(pretokens, pretoken)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       TRUST_TOKEN_PRETOKEN_free(pretoken);
       goto err;
     }
@@ -242,7 +239,6 @@
     EC_SCALAR r;
     if (!ec_random_nonzero_scalar(group, &r,
                                   kDefaultAdditionalData)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       goto err;
     }
 
@@ -292,7 +288,6 @@
       !cbb_add_point(&cbb, method->group, K1) ||
       !CBB_finish(&cbb, &buf, &len) ||
       !method->hash_to_scalar(method->group, out, buf, len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -324,7 +319,6 @@
       !CBB_add_u16(&cbb, (uint16_t)index) ||
       !CBB_finish(&cbb, &buf, &len) ||
       !method->hash_to_scalar(method->group, out, buf, len)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -387,7 +381,6 @@
   // Store DLEQ proof in transcript.
   if (!scalar_to_cbb(cbb, group, &c) ||
       !scalar_to_cbb(cbb, group, &u)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
@@ -488,7 +481,6 @@
       !es ||
       !CBB_init(&batch_cbb, 0) ||
       !cbb_add_point(&batch_cbb, method->group, &key->pubs)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -508,7 +500,6 @@
 
     if (!cbb_add_point(&batch_cbb, group, &BT_affine) ||
         !cbb_add_point(&batch_cbb, group, &Z_affine)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     BTs[i] = BT;
@@ -575,7 +566,6 @@
   int ok = 0;
   STACK_OF(TRUST_TOKEN) *ret = sk_TRUST_TOKEN_new_null();
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -594,7 +584,6 @@
       !es ||
       !CBB_init(&batch_cbb, 0) ||
       !cbb_add_point(&batch_cbb, method->group, &key->pubs)) {
-    OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -613,7 +602,6 @@
 
     if (!cbb_add_point(&batch_cbb, group, &pretoken->Tp) ||
         !cbb_add_point(&batch_cbb, group, &Z_affine)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       goto err;
     }
 
@@ -644,7 +632,6 @@
     CBB_cleanup(&token_cbb);
     if (token == NULL ||
         !sk_TRUST_TOKEN_push(ret, token)) {
-      OPENSSL_PUT_ERROR(TRUST_TOKEN, ERR_R_MALLOC_FAILURE);
       TRUST_TOKEN_free(token);
       goto err;
     }
diff --git a/crypto/x509/a_digest.c b/crypto/x509/a_digest.c
index d7dcecc..4686993 100644
--- a/crypto/x509/a_digest.c
+++ b/crypto/x509/a_digest.c
@@ -68,7 +68,6 @@
 
   i = i2d(data, NULL);
   if ((str = (unsigned char *)OPENSSL_malloc(i)) == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   p = str;
diff --git a/crypto/x509/a_sign.c b/crypto/x509/a_sign.c
index 3711a00..de89fab 100644
--- a/crypto/x509/a_sign.c
+++ b/crypto/x509/a_sign.c
@@ -107,7 +107,6 @@
   buf_out = OPENSSL_malloc((unsigned int)outl);
   if ((buf_in == NULL) || (buf_out == NULL)) {
     outl = 0;
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/x509/a_verify.c b/crypto/x509/a_verify.c
index af2c914..a70769f 100644
--- a/crypto/x509/a_verify.c
+++ b/crypto/x509/a_verify.c
@@ -98,7 +98,6 @@
   inl = ASN1_item_i2d(asn, &buf_in, it);
 
   if (buf_in == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/x509/asn1_gen.c b/crypto/x509/asn1_gen.c
index 989deee..937069e 100644
--- a/crypto/x509/asn1_gen.c
+++ b/crypto/x509/asn1_gen.c
@@ -581,7 +581,6 @@
     return 0;
   }
   if (!ASN1_BIT_STRING_set_bit(bitstr, (int)bitnum, 1)) {
-    OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   return 1;
diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c
index 3ad8128..0283a0d 100644
--- a/crypto/x509/by_dir.c
+++ b/crypto/x509/by_dir.c
@@ -211,7 +211,6 @@
       if (ctx->dirs == NULL) {
         ctx->dirs = sk_BY_DIR_ENTRY_new_null();
         if (!ctx->dirs) {
-          OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
           return 0;
         }
       }
@@ -300,7 +299,6 @@
       ent = sk_BY_DIR_ENTRY_value(ctx->dirs, i);
       j = strlen(ent->dir) + 1 + 8 + 6 + 1 + 1;
       if (!BUF_MEM_grow(b, j)) {
-        OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
         goto finish;
       }
       if (type == X509_LU_CRL && ent->hashes) {
diff --git a/crypto/x509/policy.c b/crypto/x509/policy.c
index 393cb84..47ac2d8 100644
--- a/crypto/x509/policy.c
+++ b/crypto/x509/policy.c
@@ -109,7 +109,6 @@
   assert(!is_any_policy(policy));
   X509_POLICY_NODE *node = OPENSSL_malloc(sizeof(X509_POLICY_NODE));
   if (node == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(node, 0, sizeof(X509_POLICY_NODE));
@@ -137,13 +136,11 @@
 static X509_POLICY_LEVEL *x509_policy_level_new(void) {
   X509_POLICY_LEVEL *level = OPENSSL_malloc(sizeof(X509_POLICY_LEVEL));
   if (level == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memset(level, 0, sizeof(X509_POLICY_LEVEL));
   level->nodes = sk_X509_POLICY_NODE_new(x509_policy_node_cmp);
   if (level->nodes == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     x509_policy_level_free(level);
     return NULL;
   }
@@ -188,7 +185,6 @@
   for (size_t i = 0; i < sk_X509_POLICY_NODE_num(nodes); i++) {
     X509_POLICY_NODE *node = sk_X509_POLICY_NODE_value(nodes, i);
     if (!sk_X509_POLICY_NODE_push(level->nodes, node)) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     sk_X509_POLICY_NODE_set(nodes, i, NULL);
@@ -287,7 +283,6 @@
   if (previous_level_has_any_policy) {
     new_nodes = sk_X509_POLICY_NODE_new_null();
     if (new_nodes == NULL) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     for (size_t i = 0; i < sk_POLICYINFO_num(policies); i++) {
@@ -300,7 +295,6 @@
         if (node == NULL ||  //
             !sk_X509_POLICY_NODE_push(new_nodes, node)) {
           x509_policy_node_free(node);
-          OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
           goto err;
         }
       }
@@ -397,7 +391,6 @@
       // as part of RFC 5280, section 6.1.4, step (b.1).
       new_nodes = sk_X509_POLICY_NODE_new_null();
       if (new_nodes == NULL) {
-        OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       const ASN1_OBJECT *last_policy = NULL;
@@ -442,7 +435,6 @@
   if (mappings == NULL) {
     mappings = sk_POLICY_MAPPING_new_null();
     if (mappings == NULL) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       goto err;
     }
   }
@@ -471,7 +463,6 @@
   // Convert |mappings| to our "expected_policy_set" representation.
   next = x509_policy_level_new();
   if (next == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   next->has_any_policy = level->has_any_policy;
@@ -689,7 +680,6 @@
 
   levels = sk_X509_POLICY_LEVEL_new_null();
   if (levels == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
@@ -727,7 +717,6 @@
 
     // Insert into the list.
     if (!sk_X509_POLICY_LEVEL_push(levels, level)) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     X509_POLICY_LEVEL *current_level = level;
diff --git a/crypto/x509/x509_att.c b/crypto/x509/x509_att.c
index 4a4ee47..0dda757 100644
--- a/crypto/x509/x509_att.c
+++ b/crypto/x509/x509_att.c
@@ -125,7 +125,7 @@
 
   if (x == NULL) {
     OPENSSL_PUT_ERROR(X509, ERR_R_PASSED_NULL_PARAMETER);
-    goto err2;
+    goto err;
   }
 
   if (*x == NULL) {
@@ -137,7 +137,7 @@
   }
 
   if ((new_attr = X509_ATTRIBUTE_dup(attr)) == NULL) {
-    goto err2;
+    goto err;
   }
   if (!sk_X509_ATTRIBUTE_push(sk, new_attr)) {
     goto err;
@@ -147,8 +147,6 @@
   }
   return sk;
 err:
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
-err2:
   if (new_attr != NULL) {
     X509_ATTRIBUTE_free(new_attr);
   }
@@ -226,7 +224,6 @@
 
   if ((attr == NULL) || (*attr == NULL)) {
     if ((ret = X509_ATTRIBUTE_new()) == NULL) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       return NULL;
     }
   } else {
@@ -326,7 +323,6 @@
   }
   return 1;
 err:
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
   ASN1_TYPE_free(ttmp);
   ASN1_STRING_free(stmp);
   return 0;
diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c
index b640413..b696b94 100644
--- a/crypto/x509/x509_cmp.c
+++ b/crypto/x509/x509_cmp.c
@@ -286,7 +286,6 @@
 STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain) {
   STACK_OF(X509) *ret = sk_X509_dup(chain);
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_X509_num(ret); i++) {
diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c
index 7a2d3a2..2ec8971 100644
--- a/crypto/x509/x509_lu.c
+++ b/crypto/x509/x509_lu.c
@@ -320,7 +320,6 @@
 
   X509_OBJECT *const obj = (X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
   if (obj == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return 0;
   }
 
diff --git a/crypto/x509/x509_obj.c b/crypto/x509/x509_obj.c
index 6caae4d..ed6dcc6 100644
--- a/crypto/x509/x509_obj.c
+++ b/crypto/x509/x509_obj.c
@@ -119,7 +119,7 @@
     num = ne->value->length;
     if (num > NAME_ONELINE_MAX) {
       OPENSSL_PUT_ERROR(X509, X509_R_NAME_TOO_LONG);
-      goto end;
+      goto err;
     }
     q = ne->value->data;
 
@@ -155,7 +155,7 @@
     l += 1 + l1 + 1 + l2;
     if (l > NAME_ONELINE_MAX) {
       OPENSSL_PUT_ERROR(X509, X509_R_NAME_TOO_LONG);
-      goto end;
+      goto err;
     }
     if (b != NULL) {
       if (!BUF_MEM_grow(b, l + 1)) {
@@ -201,8 +201,6 @@
   }
   return p;
 err:
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
-end:
   BUF_MEM_free(b);
   return NULL;
 }
diff --git a/crypto/x509/x509_trs.c b/crypto/x509/x509_trs.c
index 49c66c1..1329a9f 100644
--- a/crypto/x509/x509_trs.c
+++ b/crypto/x509/x509_trs.c
@@ -183,7 +183,6 @@
   // Need a new entry
   if (idx == -1) {
     if (!(trtmp = OPENSSL_malloc(sizeof(X509_TRUST)))) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     trtmp->flags = X509_TRUST_DYNAMIC;
@@ -194,7 +193,6 @@
   // Duplicate the supplied name.
   name_dup = OPENSSL_strdup(name);
   if (name_dup == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     if (idx == -1) {
       OPENSSL_free(trtmp);
     }
@@ -219,12 +217,10 @@
   // If its a new entry manage the dynamic table
   if (idx == -1) {
     if (!trtable && !(trtable = sk_X509_TRUST_new(tr_cmp))) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       trtable_free(trtmp);
       return 0;
     }
     if (!sk_X509_TRUST_push(trtable, trtmp)) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       trtable_free(trtmp);
       return 0;
     }
diff --git a/crypto/x509/x509_v3.c b/crypto/x509/x509_v3.c
index dd84352..0d4ecfa 100644
--- a/crypto/x509/x509_v3.c
+++ b/crypto/x509/x509_v3.c
@@ -182,7 +182,6 @@
   }
   return sk;
 err:
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
 err2:
   X509_EXTENSION_free(new_ex);
   if (free_sk) {
@@ -213,7 +212,6 @@
 
   if ((ex == NULL) || (*ex == NULL)) {
     if ((ret = X509_EXTENSION_new()) == NULL) {
-      OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
       return NULL;
     }
   } else {
diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c
index 9288292..7f3e232 100644
--- a/crypto/x509/x509_vfy.c
+++ b/crypto/x509/x509_vfy.c
@@ -205,7 +205,6 @@
   // the first entry is in place
   ctx->chain = sk_X509_new_null();
   if (ctx->chain == NULL || !sk_X509_push(ctx->chain, ctx->cert)) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     ctx->error = X509_V_ERR_OUT_OF_MEM;
     goto end;
   }
@@ -214,7 +213,6 @@
 
   // We use a temporary STACK so we can chop and hack at it.
   if (ctx->untrusted != NULL && (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     ctx->error = X509_V_ERR_OUT_OF_MEM;
     goto end;
   }
@@ -262,7 +260,6 @@
       xtmp = find_issuer(ctx, sktmp, x);
       if (xtmp != NULL) {
         if (!sk_X509_push(ctx->chain, xtmp)) {
-          OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
           ctx->error = X509_V_ERR_OUT_OF_MEM;
           ok = 0;
           goto end;
@@ -358,7 +355,6 @@
       x = xtmp;
       if (!sk_X509_push(ctx->chain, x)) {
         X509_free(xtmp);
-        OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
         ctx->error = X509_V_ERR_OUT_OF_MEM;
         ok = 0;
         goto end;
@@ -1994,7 +1990,6 @@
   return crl;
 
 memerr:
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
   if (crl) {
     X509_CRL_free(crl);
   }
@@ -2145,7 +2140,6 @@
   X509_STORE_CTX *ctx;
   ctx = (X509_STORE_CTX *)OPENSSL_malloc(sizeof(X509_STORE_CTX));
   if (!ctx) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   X509_STORE_CTX_zero(ctx);
@@ -2265,7 +2259,6 @@
   }
 
   OPENSSL_memset(ctx, 0, sizeof(X509_STORE_CTX));
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
   return 0;
 }
 
diff --git a/crypto/x509/x509name.c b/crypto/x509/x509name.c
index fcfbc0c..cc86e28 100644
--- a/crypto/x509/x509name.c
+++ b/crypto/x509/x509name.c
@@ -263,7 +263,6 @@
   }
   new_name->set = set;
   if (!sk_X509_NAME_ENTRY_insert(sk, new_name, loc)) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   if (inc) {
diff --git a/crypto/x509/x509spki.c b/crypto/x509/x509spki.c
index 8251534..8ff2053 100644
--- a/crypto/x509/x509spki.c
+++ b/crypto/x509/x509spki.c
@@ -90,7 +90,6 @@
     return NULL;
   }
   if (!(spki_der = OPENSSL_malloc(spki_len))) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   if (!EVP_DecodeBase64(spki_der, &spki_len, spki_len, (const uint8_t *)str,
@@ -119,13 +118,11 @@
   }
   der_spki = OPENSSL_malloc(der_len);
   if (der_spki == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   b64_str = OPENSSL_malloc(b64_len);
   if (b64_str == NULL) {
     OPENSSL_free(der_spki);
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   p = der_spki;
diff --git a/crypto/x509/x_crl.c b/crypto/x509/x_crl.c
index 1480448..9c4c116 100644
--- a/crypto/x509/x_crl.c
+++ b/crypto/x509/x_crl.c
@@ -372,7 +372,6 @@
     inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp);
   }
   if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   asn1_encoding_clear(&inf->enc);
diff --git a/crypto/x509/x_info.c b/crypto/x509/x_info.c
index e6f9be2..0f074f6 100644
--- a/crypto/x509/x_info.c
+++ b/crypto/x509/x_info.c
@@ -66,7 +66,6 @@
 
   ret = (X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
diff --git a/crypto/x509/x_name.c b/crypto/x509/x_name.c
index f017423..a65c116 100644
--- a/crypto/x509/x_name.c
+++ b/crypto/x509/x_name.c
@@ -152,7 +152,6 @@
   return 1;
 
 memerr:
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
   if (ret) {
     if (ret->entries) {
       sk_X509_NAME_ENTRY_free(ret->entries);
@@ -279,23 +278,23 @@
   STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname =
       sk_STACK_OF_X509_NAME_ENTRY_new_null();
   if (!intname) {
-    goto memerr;
+    goto err;
   }
   for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
     entry = sk_X509_NAME_ENTRY_value(a->entries, i);
     if (entry->set != set) {
       entries = sk_X509_NAME_ENTRY_new_null();
       if (!entries) {
-        goto memerr;
+        goto err;
       }
       if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname, entries)) {
         sk_X509_NAME_ENTRY_free(entries);
-        goto memerr;
+        goto err;
       }
       set = entry->set;
     }
     if (!sk_X509_NAME_ENTRY_push(entries, entry)) {
-      goto memerr;
+      goto err;
     }
   }
   ASN1_VALUE *intname_val = (ASN1_VALUE *)intname;
@@ -305,7 +304,7 @@
     goto err;
   }
   if (!BUF_MEM_grow(a->bytes, len)) {
-    goto memerr;
+    goto err;
   }
   p = (unsigned char *)a->bytes->data;
   if (ASN1_item_ex_i2d(&intname_val, &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
@@ -315,8 +314,6 @@
   sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, local_sk_X509_NAME_ENTRY_free);
   a->modified = 0;
   return 1;
-memerr:
-  OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
 err:
   sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, local_sk_X509_NAME_ENTRY_free);
   return 0;
diff --git a/crypto/x509/x_pkey.c b/crypto/x509/x_pkey.c
index 52bc5b6..d48ecd1 100644
--- a/crypto/x509/x_pkey.c
+++ b/crypto/x509/x_pkey.c
@@ -69,7 +69,6 @@
 X509_PKEY *X509_PKEY_new(void) {
   X509_PKEY *ret = OPENSSL_malloc(sizeof(X509_PKEY));
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   OPENSSL_memset(ret, 0, sizeof(X509_PKEY));
diff --git a/crypto/x509v3/v3_akey.c b/crypto/x509v3/v3_akey.c
index b4093bf..2af596a 100644
--- a/crypto/x509v3/v3_akey.c
+++ b/crypto/x509v3/v3_akey.c
@@ -201,7 +201,6 @@
   if (isname) {
     if (!(gens = sk_GENERAL_NAME_new_null()) || !(gen = GENERAL_NAME_new()) ||
         !sk_GENERAL_NAME_push(gens, gen)) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     gen->type = GEN_DIRNAME;
diff --git a/crypto/x509v3/v3_alt.c b/crypto/x509v3/v3_alt.c
index f10c1ce..858ef4d 100644
--- a/crypto/x509v3/v3_alt.c
+++ b/crypto/x509v3/v3_alt.c
@@ -275,7 +275,6 @@
                             const STACK_OF(CONF_VALUE) *nval) {
   GENERAL_NAMES *gens = sk_GENERAL_NAME_new_null();
   if (gens == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -326,7 +325,6 @@
   for (size_t j = 0; j < sk_GENERAL_NAME_num(ialt); j++) {
     GENERAL_NAME *gen = sk_GENERAL_NAME_value(ialt, j);
     if (!sk_GENERAL_NAME_push(gens, gen)) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     // Ownership of |gen| has moved from |ialt| to |gens|.
@@ -345,7 +343,6 @@
                              const STACK_OF(CONF_VALUE) *nval) {
   GENERAL_NAMES *gens = sk_GENERAL_NAME_new_null();
   if (gens == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -407,14 +404,12 @@
       i--;
     }
     if (!email || !(gen = GENERAL_NAME_new())) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     gen->d.ia5 = email;
     email = NULL;
     gen->type = GEN_EMAIL;
     if (!sk_GENERAL_NAME_push(gens, gen)) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     gen = NULL;
@@ -433,7 +428,6 @@
                                  const STACK_OF(CONF_VALUE) *nval) {
   GENERAL_NAMES *gens = sk_GENERAL_NAME_new_null();
   if (gens == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -470,7 +464,6 @@
   } else {
     gen = GENERAL_NAME_new();
     if (gen == NULL) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       return NULL;
     }
   }
@@ -482,7 +475,6 @@
       ASN1_IA5STRING *str = ASN1_IA5STRING_new();
       if (str == NULL || !ASN1_STRING_set(str, value, strlen(value))) {
         ASN1_STRING_free(str);
-        OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
         goto err;
       }
       gen->type = gen_type;
diff --git a/crypto/x509v3/v3_bcons.c b/crypto/x509v3/v3_bcons.c
index c558c78..e614b8e 100644
--- a/crypto/x509v3/v3_bcons.c
+++ b/crypto/x509v3/v3_bcons.c
@@ -110,7 +110,6 @@
                                    const STACK_OF(CONF_VALUE) *values) {
   BASIC_CONSTRAINTS *bcons = NULL;
   if (!(bcons = BASIC_CONSTRAINTS_new())) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(values); i++) {
diff --git a/crypto/x509v3/v3_bitst.c b/crypto/x509v3/v3_bitst.c
index d87dcf9..1201738 100644
--- a/crypto/x509v3/v3_bitst.c
+++ b/crypto/x509v3/v3_bitst.c
@@ -105,7 +105,6 @@
                                  const STACK_OF(CONF_VALUE) *nval) {
   ASN1_BIT_STRING *bs;
   if (!(bs = ASN1_BIT_STRING_new())) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -114,7 +113,6 @@
     for (bnam = method->usr_data; bnam->lname; bnam++) {
       if (!strcmp(bnam->sname, val->name) || !strcmp(bnam->lname, val->name)) {
         if (!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) {
-          OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
           ASN1_BIT_STRING_free(bs);
           return NULL;
         }
diff --git a/crypto/x509v3/v3_conf.c b/crypto/x509v3/v3_conf.c
index a4f172d..ebf33f1 100644
--- a/crypto/x509v3/v3_conf.c
+++ b/crypto/x509v3/v3_conf.c
@@ -236,7 +236,6 @@
   return ext;
 
 merr:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
   return NULL;
 }
 
@@ -314,7 +313,6 @@
   }
 
   if (!(oct = ASN1_OCTET_STRING_new())) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/x509v3/v3_cpols.c b/crypto/x509v3/v3_cpols.c
index 84d458c..e66e260 100644
--- a/crypto/x509v3/v3_cpols.c
+++ b/crypto/x509v3/v3_cpols.c
@@ -153,7 +153,6 @@
                          const char *value) {
   STACK_OF(POLICYINFO) *pols = sk_POLICYINFO_new_null();
   if (pols == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   STACK_OF(CONF_VALUE) *vals = X509V3_parse_list(value);
@@ -195,7 +194,6 @@
       }
       pol = POLICYINFO_new();
       if (pol == NULL) {
-        OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
         ASN1_OBJECT_free(pobj);
         goto err;
       }
@@ -203,7 +201,6 @@
     }
     if (!sk_POLICYINFO_push(pols, pol)) {
       POLICYINFO_free(pol);
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
   }
@@ -221,7 +218,7 @@
   POLICYINFO *pol;
   POLICYQUALINFO *qual;
   if (!(pol = POLICYINFO_new())) {
-    goto merr;
+    goto err;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(polstrs); i++) {
     const CONF_VALUE *cnf = sk_CONF_VALUE_value(polstrs, i);
@@ -239,10 +236,10 @@
         pol->qualifiers = sk_POLICYQUALINFO_new_null();
       }
       if (!(qual = POLICYQUALINFO_new())) {
-        goto merr;
+        goto err;
       }
       if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) {
-        goto merr;
+        goto err;
       }
       qual->pqualid = OBJ_nid2obj(NID_id_qt_cps);
       if (qual->pqualid == NULL) {
@@ -254,7 +251,7 @@
         goto err;
       }
       if (!ASN1_STRING_set(qual->d.cpsuri, cnf->value, strlen(cnf->value))) {
-        goto merr;
+        goto err;
       }
     } else if (x509v3_conf_name_matches(cnf->name, "userNotice")) {
       if (*cnf->value != '@') {
@@ -277,7 +274,7 @@
         pol->qualifiers = sk_POLICYQUALINFO_new_null();
       }
       if (!sk_POLICYQUALINFO_push(pol->qualifiers, qual)) {
-        goto merr;
+        goto err;
       }
     } else {
       OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_OPTION);
@@ -293,9 +290,6 @@
 
   return pol;
 
-merr:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
-
 err:
   POLICYINFO_free(pol);
   return NULL;
@@ -307,7 +301,7 @@
   USERNOTICE *notice;
   POLICYQUALINFO *qual;
   if (!(qual = POLICYQUALINFO_new())) {
-    goto merr;
+    goto err;
   }
   qual->pqualid = OBJ_nid2obj(NID_id_qt_unotice);
   if (qual->pqualid == NULL) {
@@ -315,7 +309,7 @@
     goto err;
   }
   if (!(notice = USERNOTICE_new())) {
-    goto merr;
+    goto err;
   }
   qual->d.usernotice = notice;
   for (size_t i = 0; i < sk_CONF_VALUE_num(unot); i++) {
@@ -323,16 +317,16 @@
     if (!strcmp(cnf->name, "explicitText")) {
       notice->exptext = ASN1_VISIBLESTRING_new();
       if (notice->exptext == NULL) {
-        goto merr;
+        goto err;
       }
       if (!ASN1_STRING_set(notice->exptext, cnf->value, strlen(cnf->value))) {
-        goto merr;
+        goto err;
       }
     } else if (!strcmp(cnf->name, "organization")) {
       NOTICEREF *nref;
       if (!notice->noticeref) {
         if (!(nref = NOTICEREF_new())) {
-          goto merr;
+          goto err;
         }
         notice->noticeref = nref;
       } else {
@@ -345,14 +339,14 @@
       }
       if (!ASN1_STRING_set(nref->organization, cnf->value,
                            strlen(cnf->value))) {
-        goto merr;
+        goto err;
       }
     } else if (!strcmp(cnf->name, "noticeNumbers")) {
       NOTICEREF *nref;
       STACK_OF(CONF_VALUE) *nos;
       if (!notice->noticeref) {
         if (!(nref = NOTICEREF_new())) {
-          goto merr;
+          goto err;
         }
         notice->noticeref = nref;
       } else {
@@ -384,9 +378,6 @@
 
   return qual;
 
-merr:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
-
 err:
   POLICYQUALINFO_free(qual);
   return NULL;
@@ -403,7 +394,6 @@
     }
     if (!sk_ASN1_INTEGER_push(nnums, aint)) {
       ASN1_INTEGER_free(aint);
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       return 0;
     }
   }
diff --git a/crypto/x509v3/v3_crld.c b/crypto/x509v3/v3_crld.c
index a3cae42..4162c35 100644
--- a/crypto/x509v3/v3_crld.c
+++ b/crypto/x509v3/v3_crld.c
@@ -319,7 +319,7 @@
   GENERAL_NAMES *gens = NULL;
   GENERAL_NAME *gen = NULL;
   if (!(crld = sk_DIST_POINT_new_null())) {
-    goto merr;
+    goto err;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
     DIST_POINT *point;
@@ -335,28 +335,28 @@
       }
       if (!sk_DIST_POINT_push(crld, point)) {
         DIST_POINT_free(point);
-        goto merr;
+        goto err;
       }
     } else {
       if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) {
         goto err;
       }
       if (!(gens = GENERAL_NAMES_new())) {
-        goto merr;
+        goto err;
       }
       if (!sk_GENERAL_NAME_push(gens, gen)) {
-        goto merr;
+        goto err;
       }
       gen = NULL;
       if (!(point = DIST_POINT_new())) {
-        goto merr;
+        goto err;
       }
       if (!sk_DIST_POINT_push(crld, point)) {
         DIST_POINT_free(point);
-        goto merr;
+        goto err;
       }
       if (!(point->distpoint = DIST_POINT_NAME_new())) {
-        goto merr;
+        goto err;
       }
       point->distpoint->name.fullname = gens;
       point->distpoint->type = 0;
@@ -365,8 +365,6 @@
   }
   return crld;
 
-merr:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
 err:
   GENERAL_NAME_free(gen);
   GENERAL_NAMES_free(gens);
@@ -449,7 +447,7 @@
                      const STACK_OF(CONF_VALUE) *nval) {
   ISSUING_DIST_POINT *idp = ISSUING_DIST_POINT_new();
   if (!idp) {
-    goto merr;
+    goto err;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
     const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i);
@@ -490,8 +488,6 @@
   }
   return idp;
 
-merr:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
 err:
   ISSUING_DIST_POINT_free(idp);
   return NULL;
diff --git a/crypto/x509v3/v3_extku.c b/crypto/x509v3/v3_extku.c
index 46f40a7..d678ac7 100644
--- a/crypto/x509v3/v3_extku.c
+++ b/crypto/x509v3/v3_extku.c
@@ -129,7 +129,6 @@
                                     const STACK_OF(CONF_VALUE) *nval) {
   EXTENDED_KEY_USAGE *extku = sk_ASN1_OBJECT_new_null();
   if (extku == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
diff --git a/crypto/x509v3/v3_ia5.c b/crypto/x509v3/v3_ia5.c
index 8104e7b..e0f9e6b 100644
--- a/crypto/x509v3/v3_ia5.c
+++ b/crypto/x509v3/v3_ia5.c
@@ -76,7 +76,6 @@
     return NULL;
   }
   if (!(tmp = OPENSSL_malloc(ia5->length + 1))) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   OPENSSL_memcpy(tmp, ia5->data, ia5->length);
@@ -100,7 +99,6 @@
   }
   return ia5;
 err:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
   return NULL;
 }
 
diff --git a/crypto/x509v3/v3_info.c b/crypto/x509v3/v3_info.c
index e6b3cc5..2ac9221 100644
--- a/crypto/x509v3/v3_info.c
+++ b/crypto/x509v3/v3_info.c
@@ -157,7 +157,6 @@
 
   return tret;
 err:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
   if (ret == NULL && tret != NULL) {
     sk_CONF_VALUE_pop_free(tret, X509V3_conf_free);
   }
@@ -171,14 +170,12 @@
   ACCESS_DESCRIPTION *acc;
   char *objtmp, *ptmp;
   if (!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
     const CONF_VALUE *cnf = sk_CONF_VALUE_value(nval, i);
     if (!(acc = ACCESS_DESCRIPTION_new()) ||
         !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     ptmp = strchr(cnf->name, ';');
@@ -194,7 +191,6 @@
       goto err;
     }
     if (!(objtmp = OPENSSL_malloc(objlen + 1))) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
     OPENSSL_strlcpy(objtmp, cnf->name, objlen + 1);
diff --git a/crypto/x509v3/v3_lib.c b/crypto/x509v3/v3_lib.c
index 51d15bb..d006a5e 100644
--- a/crypto/x509v3/v3_lib.c
+++ b/crypto/x509v3/v3_lib.c
@@ -79,12 +79,10 @@
 
 int X509V3_EXT_add(X509V3_EXT_METHOD *ext) {
   if (!ext_list && !(ext_list = sk_X509V3_EXT_METHOD_new(ext_stack_cmp))) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     ext_list_free(ext);
     return 0;
   }
   if (!sk_X509V3_EXT_METHOD_push(ext_list, ext)) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     ext_list_free(ext);
     return 0;
   }
@@ -168,7 +166,6 @@
   }
   if (!(tmpext =
             (X509V3_EXT_METHOD *)OPENSSL_malloc(sizeof(X509V3_EXT_METHOD)))) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return 0;
   }
   *tmpext = *ext;
diff --git a/crypto/x509v3/v3_ncons.c b/crypto/x509v3/v3_ncons.c
index 1b3b9f8..ac9559f 100644
--- a/crypto/x509v3/v3_ncons.c
+++ b/crypto/x509v3/v3_ncons.c
@@ -127,7 +127,7 @@
   GENERAL_SUBTREE *sub = NULL;
   ncons = NAME_CONSTRAINTS_new();
   if (!ncons) {
-    goto memerr;
+    goto err;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(nval); i++) {
     const CONF_VALUE *val = sk_CONF_VALUE_value(nval, i);
@@ -151,15 +151,13 @@
       *ptree = sk_GENERAL_SUBTREE_new_null();
     }
     if (!*ptree || !sk_GENERAL_SUBTREE_push(*ptree, sub)) {
-      goto memerr;
+      goto err;
     }
     sub = NULL;
   }
 
   return ncons;
 
-memerr:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
 err:
   NAME_CONSTRAINTS_free(ncons);
   GENERAL_SUBTREE_free(sub);
diff --git a/crypto/x509v3/v3_pci.c b/crypto/x509v3/v3_pci.c
index e680b5b..f6b3802 100644
--- a/crypto/x509v3/v3_pci.c
+++ b/crypto/x509v3/v3_pci.c
@@ -122,7 +122,6 @@
     if (!*policy) {
       *policy = ASN1_OCTET_STRING_new();
       if (!*policy) {
-        OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
         X509V3_conf_err(val);
         return 0;
       }
@@ -150,7 +149,6 @@
         // too!
         (*policy)->data = NULL;
         (*policy)->length = 0;
-        OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
         X509V3_conf_err(val);
         goto err;
       }
@@ -170,7 +168,6 @@
         // too!
         (*policy)->data = NULL;
         (*policy)->length = 0;
-        OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
         X509V3_conf_err(val);
         goto err;
       }
@@ -180,7 +177,6 @@
       goto err;
     }
     if (!tmp_data) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       X509V3_conf_err(val);
       goto err;
     }
@@ -246,7 +242,6 @@
 
   pci = PROXY_CERT_INFO_EXTENSION_new();
   if (!pci) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/x509v3/v3_pcons.c b/crypto/x509v3/v3_pcons.c
index 4cb5541..7b70a4e 100644
--- a/crypto/x509v3/v3_pcons.c
+++ b/crypto/x509v3/v3_pcons.c
@@ -112,7 +112,6 @@
                                     const STACK_OF(CONF_VALUE) *values) {
   POLICY_CONSTRAINTS *pcons = NULL;
   if (!(pcons = POLICY_CONSTRAINTS_new())) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
   for (size_t i = 0; i < sk_CONF_VALUE_num(values); i++) {
diff --git a/crypto/x509v3/v3_pmaps.c b/crypto/x509v3/v3_pmaps.c
index dae4b66..cd8efd6 100644
--- a/crypto/x509v3/v3_pmaps.c
+++ b/crypto/x509v3/v3_pmaps.c
@@ -117,7 +117,6 @@
                                  const STACK_OF(CONF_VALUE) *nval) {
   POLICY_MAPPINGS *pmaps = sk_POLICY_MAPPING_new_null();
   if (pmaps == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -132,7 +131,6 @@
     POLICY_MAPPING *pmap = POLICY_MAPPING_new();
     if (pmap == NULL || !sk_POLICY_MAPPING_push(pmaps, pmap)) {
       POLICY_MAPPING_free(pmap);
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       goto err;
     }
 
diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c
index 4415132..9f22f1a 100644
--- a/crypto/x509v3/v3_purp.c
+++ b/crypto/x509v3/v3_purp.c
@@ -224,7 +224,6 @@
   // Need a new entry
   if (idx == -1) {
     if (!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       return 0;
     }
     ptmp->flags = X509_PURPOSE_DYNAMIC;
@@ -236,7 +235,6 @@
   name_dup = OPENSSL_strdup(name);
   sname_dup = OPENSSL_strdup(sname);
   if (name_dup == NULL || sname_dup == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     if (name_dup != NULL) {
       OPENSSL_free(name_dup);
     }
@@ -270,12 +268,10 @@
   // If its a new entry manage the dynamic table
   if (idx == -1) {
     if (!xptable && !(xptable = sk_X509_PURPOSE_new(xp_cmp))) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       xptable_free(ptmp);
       return 0;
     }
     if (!sk_X509_PURPOSE_push(xptable, ptmp)) {
-      OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
       xptable_free(ptmp);
       return 0;
     }
diff --git a/crypto/x509v3/v3_skey.c b/crypto/x509v3/v3_skey.c
index eac7c1d..cae776f 100644
--- a/crypto/x509v3/v3_skey.c
+++ b/crypto/x509v3/v3_skey.c
@@ -78,7 +78,6 @@
   long length;
 
   if (!(oct = ASN1_OCTET_STRING_new())) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -109,7 +108,6 @@
   }
 
   if (!(oct = ASN1_OCTET_STRING_new())) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     return NULL;
   }
 
@@ -138,7 +136,6 @@
   }
 
   if (!ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     goto err;
   }
 
diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c
index 7e1ce51..9281e30 100644
--- a/crypto/x509v3/v3_utl.c
+++ b/crypto/x509v3/v3_utl.c
@@ -96,7 +96,7 @@
   char *tname = NULL, *tvalue = NULL;
   int extlist_was_null = *extlist == NULL;
   if (name && !(tname = OPENSSL_strdup(name))) {
-    goto malloc_err;
+    goto err;
   }
   if (!omit_value) {
     // |CONF_VALUE| cannot represent strings with NULs.
@@ -106,24 +106,22 @@
     }
     tvalue = OPENSSL_strndup(value, value_len);
     if (tvalue == NULL) {
-      goto malloc_err;
+      goto err;
     }
   }
   if (!(vtmp = CONF_VALUE_new())) {
-    goto malloc_err;
+    goto err;
   }
   if (!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) {
-    goto malloc_err;
+    goto err;
   }
   vtmp->section = NULL;
   vtmp->name = tname;
   vtmp->value = tvalue;
   if (!sk_CONF_VALUE_push(*extlist, vtmp)) {
-    goto malloc_err;
+    goto err;
   }
   return 1;
-malloc_err:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
 err:
   if (extlist_was_null) {
     sk_CONF_VALUE_free(*extlist);
@@ -186,7 +184,6 @@
   len = strlen(tmp) + 3;
   ret = OPENSSL_malloc(len);
   if (ret == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     OPENSSL_free(tmp);
     return NULL;
   }
@@ -212,7 +209,6 @@
   }
   if (!(bntmp = ASN1_ENUMERATED_to_BN(a, NULL)) ||
       !(strtmp = bignum_to_string(bntmp))) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
   }
   BN_free(bntmp);
   return strtmp;
@@ -226,7 +222,6 @@
   }
   if (!(bntmp = ASN1_INTEGER_to_BN(a, NULL)) ||
       !(strtmp = bignum_to_string(bntmp))) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
   }
   BN_free(bntmp);
   return strtmp;
@@ -366,7 +361,6 @@
   // We are going to modify the line so copy it first
   linebuf = OPENSSL_strdup(line);
   if (linebuf == NULL) {
-    OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
     goto err;
   }
   state = HDR_NAME;
@@ -496,7 +490,6 @@
   return (char *)ret;
 
 err:
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
   CBB_cleanup(&cbb);
   return NULL;
 }
@@ -540,7 +533,6 @@
 
 err:
   OPENSSL_free(hexbuf);
-  OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
   return NULL;
 
 badhex: