在 nullptr 上调用 OpenSSL BIO/EC_KEY/EVP_KEY/..._free 函数是否安全?
Is it safe to call OpenSSL BIO/EC_KEY/EVP_KEY/..._free functions on nullptr?
我正在编写的小应用程序中有大量 OpenSSL 资源。我通常将它们包装在带有自定义删除器的 unique_ptr 中,例如:
std::unique_ptr<BIO, decltype(&BIO_free)> bio(BIO_new(), BIO_free);
现在,这简单明了。
但是,有时我需要对原始指针进行操作,并且只有在某些处理完成后才将其封装在 unique_ptr
中
BIO* bioRaw;
std::unique_ptr<BIO, decltype(&BIO_free)> bio(bioRaw, BIO_free);
我是否需要检查 bioRaw 是否为 nullptr?或者 BIO_free(以及来自 OpenSSL 的 _free 函数系列)是否可以使用 nullptr?
根据 release notes 它在版本 0.9.2b 中是安全的,因此在以后的版本中可能是安全的:
Changes between 0.9.1c and 0.9.2b [22 Mar 1999]
.....
*) Make all *_free functions accept a NULL pointer.
[Frans Heymans ]
注意:看起来此行为已被 删除并
重新实现 因为
许可问题,但我认为在删除之间没有发布任何版本
和重新实现。
我正在编写的小应用程序中有大量 OpenSSL 资源。我通常将它们包装在带有自定义删除器的 unique_ptr 中,例如:
std::unique_ptr<BIO, decltype(&BIO_free)> bio(BIO_new(), BIO_free);
现在,这简单明了。
但是,有时我需要对原始指针进行操作,并且只有在某些处理完成后才将其封装在 unique_ptr
中BIO* bioRaw;
std::unique_ptr<BIO, decltype(&BIO_free)> bio(bioRaw, BIO_free);
我是否需要检查 bioRaw 是否为 nullptr?或者 BIO_free(以及来自 OpenSSL 的 _free 函数系列)是否可以使用 nullptr?
根据 release notes 它在版本 0.9.2b 中是安全的,因此在以后的版本中可能是安全的:
Changes between 0.9.1c and 0.9.2b [22 Mar 1999]
.....
*) Make all *_free functions accept a NULL pointer. [Frans Heymans ]
注意:看起来此行为已被 删除并 重新实现 因为 许可问题,但我认为在删除之间没有发布任何版本 和重新实现。