Skip to content

Commit

Permalink
Fix memory leaks when parsing PKCS#12 containers
Browse files Browse the repository at this point in the history
Frees unnecessary objects when parsing PKCS#12 containers, thus
fixing memory leak.
  • Loading branch information
John Galea authored and zuul[bot] committed Mar 20, 2024
1 parent b53a667 commit 1e49183
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/openssl_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,7 @@ SSL_X509_Ptr _parseCertificateFromPkcs12(PKCS12 *p12, const std::string &pwd)
X509 *cert = nullptr;
OpensslCallIsPositive::callChecked(
lib::OpenSSLLib::SSL_PKCS12_parse, p12, pwd.c_str(), &pkey, &cert, nullptr);
lib::OpenSSLLib::SSL_EVP_PKEY_free(pkey);

if (cert == nullptr) {
throw OpenSSLException("Cannot parse certificate from pkcs12 container. Not available");
Expand All @@ -1838,6 +1839,8 @@ SSL_STACK_OWNER_X509_Ptr _parseAdditionalCertsFromPkcs12(PKCS12 *p12, const std:
auto additionalCerts = createOpenSSLObject<STACK_OF(X509)>();
OpensslCallIsPositive::callChecked(
lib::OpenSSLLib::SSL_PKCS12_parse, p12, pwd.c_str(), &pkey, &cert, &additionalCerts);
lib::OpenSSLLib::SSL_EVP_PKEY_free(pkey);
lib::OpenSSLLib::SSL_X509_free(cert);

return SSL_STACK_OWNER_X509_Ptr{additionalCerts};
}
Expand Down

0 comments on commit 1e49183

Please sign in to comment.