Skip to content

Commit 1e49183

Browse files
John Galeazuul[bot]
authored andcommitted
Fix memory leaks when parsing PKCS#12 containers
Frees unnecessary objects when parsing PKCS#12 containers, thus fixing memory leak.
1 parent b53a667 commit 1e49183

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/openssl_wrap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,7 @@ SSL_X509_Ptr _parseCertificateFromPkcs12(PKCS12 *p12, const std::string &pwd)
18191819
X509 *cert = nullptr;
18201820
OpensslCallIsPositive::callChecked(
18211821
lib::OpenSSLLib::SSL_PKCS12_parse, p12, pwd.c_str(), &pkey, &cert, nullptr);
1822+
lib::OpenSSLLib::SSL_EVP_PKEY_free(pkey);
18221823

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

18421845
return SSL_STACK_OWNER_X509_Ptr{additionalCerts};
18431846
}

0 commit comments

Comments
 (0)