diff --git a/crypto/evp_extra/evp_extra_test.cc b/crypto/evp_extra/evp_extra_test.cc index 9308fe2e42d..5fd6bff8348 100644 --- a/crypto/evp_extra/evp_extra_test.cc +++ b/crypto/evp_extra/evp_extra_test.cc @@ -3061,11 +3061,14 @@ TEST_P(PerParamgenCBTest, ParamgenCallbacks) { // Generating an DH params will trigger the callback. - EVP_PKEY *pkey = EVP_PKEY_new(); ASSERT_EQ(EVP_PKEY_paramgen_init(ctx.get()), 1); ASSERT_TRUE(EVP_PKEY_CTX_ctrl_str(ctx.get(), GetParam().setup_command, GetParam().setup_arg)); - ASSERT_TRUE(EVP_PKEY_paramgen(ctx.get(), &pkey)); - ASSERT_TRUE(pkey); + { + EVP_PKEY *pkey = EVP_PKEY_new(); + ASSERT_TRUE(pkey); + ASSERT_TRUE(EVP_PKEY_paramgen(ctx.get(), &pkey)); + EVP_PKEY_free(pkey); + } // Verify that |ctx->keygen_info| has not been updated since a callback hasn't // been set. @@ -3080,9 +3083,12 @@ TEST_P(PerParamgenCBTest, ParamgenCallbacks) { EXPECT_FALSE(app_data.state); // Call key generation again to trigger the callback. - ASSERT_TRUE(EVP_PKEY_paramgen(ctx.get(), &pkey)); - ASSERT_TRUE(pkey); - bssl::UniquePtr ptr(pkey); + { + EVP_PKEY *pkey = EVP_PKEY_new(); + ASSERT_TRUE(pkey); + ASSERT_TRUE(EVP_PKEY_paramgen(ctx.get(), &pkey)); + EVP_PKEY_free(pkey); + } // The callback function should set the state to true. The contents of // |ctx->keygen_info| will only be populated once the callback has been set. @@ -3160,7 +3166,7 @@ TEST(EVPExtraTest, DSAKeygen) { bssl::UniquePtr params = dsa_paramgen(512, EVP_sha1(), copy); ASSERT_TRUE(params); const DSA* params_dsa = EVP_PKEY_get0_DSA(params.get()); - + ASSERT_TRUE(params_dsa); bssl::UniquePtr pkey1 = dsa_keygen(params, copy); ASSERT_TRUE(pkey1); diff --git a/crypto/evp_extra/p_dsa_asn1.c b/crypto/evp_extra/p_dsa_asn1.c index 4369a484b60..470d3bd04eb 100644 --- a/crypto/evp_extra/p_dsa_asn1.c +++ b/crypto/evp_extra/p_dsa_asn1.c @@ -95,8 +95,9 @@ static int dsa_pub_decode(EVP_PKEY *out, CBS *params, CBS *key) { goto err; } - EVP_PKEY_assign_DSA(out, dsa); - return 1; + if(1 == EVP_PKEY_assign_DSA(out, dsa)) { + return 1; + } err: DSA_free(dsa); @@ -168,9 +169,10 @@ static int dsa_priv_decode(EVP_PKEY *out, CBS *params, CBS *key, CBS *pubkey) { goto err; } - BN_CTX_free(ctx); - EVP_PKEY_assign_DSA(out, dsa); - return 1; + if(1 == EVP_PKEY_assign_DSA(out, dsa)) { + BN_CTX_free(ctx); + return 1; + } err: BN_CTX_free(ctx);