此代码(忽略缺乏错误处理)是否会与 OpenSSL 3.0 泄漏?
EVP_PKEY *pkey = NULL;
BIO *public_key_file = BIO_new_file("public.pem", "r");
OSSL_DECODER_CTX *dctx = OSSL_DECODER_CTX_new_for_pkey(
&pkey, "PEM", NULL, "EC",
OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
NULL, NULL
)};
OSSL_DECODER_from_bio(dctx, public_key_file);
// ...
BIO_free(public_key_file);
OSSL_DECODER_CTX_free(dctx);
或者,是否需要额外的
EVP_PKEY_free(pkey)
?
文档没有提及调用者是否需要释放密钥。
Leak_DefinitelyLost
2,653 (152 direct, 2,501 indirect) bytes in 1 blocks are definitely lost in loss record 34 of 34
0x4848899 malloc
0x4A1A5DD CRYPTO_zalloc
0x4A07FE3 EVP_PKEY_new
0x49CD1EB \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x49CC722 \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x4ABD857 \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x49CC95A \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x4ABEF97 \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x49CC95A \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x4ABE8EB \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x49CC95A \usr\lib\x86_64-linux-gnu\libcrypto.so.3
0x49CCC30 OSSL_DECODER_from_bio
所以这是一个“是”,但只有在稍后的调用加载它之后。
OSSL_DECODER_CTX_new_for_pkey
本身不分配密钥。