From 29b50eab6c709a4c84e245e259f9ff4c4c2b8d00 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Thu, 26 Feb 2015 16:22:21 -0500 Subject: Align d2i_ECPrivateKey error-handling with upstream. Upstream decided to make the caller free the scratch space rather than the callee. May as well match. (Existing code is pretty inconsistent. This API pattern needs to go.) See upstream's 9e442d485008046933cdc7da65080f436a4af089. Change-Id: I7c9fcae5778a74d6ae8e9f546e03fb2cf6e48426 Reviewed-on: https://boringssl-review.googlesource.com/3671 Reviewed-by: Adam Langley --- crypto/ec/ec_asn1.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'crypto') diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c index ce9b3f40..5b3e048f 100644 --- a/crypto/ec/ec_asn1.c +++ b/crypto/ec/ec_asn1.c @@ -309,9 +309,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) { OPENSSL_PUT_ERROR(EC, d2i_ECPrivateKey, ERR_R_MALLOC_FAILURE); goto err; } - if (a) { - *a = ret; - } } else { ret = *a; } @@ -380,17 +377,17 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const uint8_t **in, long len) { ret->enc_flag |= EC_PKEY_NO_PUBKEY; } + if (a) { + *a = ret; + } ok = 1; err: if (!ok) { - if (ret) { + if (ret && (a == NULL || *a != ret)) { EC_KEY_free(ret); } ret = NULL; - if (a) { - *a = ret; - } } if (priv_key) { -- cgit v1.2.3