PKCS12Container: fix memory leaks on exceptions

This commit is contained in:
Alexander Galanin 2020-06-04 18:11:15 +03:00
parent bc9f15e9e9
commit 29cfff29d0

View File

@ -155,6 +155,7 @@ void PKCS12Container::load(PKCS12* pPKCS12, const std::string& password)
{ {
_pX509Cert.reset(new X509Certificate(pCert, true)); _pX509Cert.reset(new X509Certificate(pCert, true));
_pkcsFriendlyName = extractFriendlyName(pCert); _pkcsFriendlyName = extractFriendlyName(pCert);
X509_free(pCert);
} }
else _pX509Cert.reset(); else _pX509Cert.reset();
@ -171,17 +172,22 @@ void PKCS12Container::load(PKCS12* pPKCS12, const std::string& password)
_caCertList.push_back(X509Certificate(pX509, true)); _caCertList.push_back(X509Certificate(pX509, true));
_caCertNames.push_back(extractFriendlyName(pX509)); _caCertNames.push_back(extractFriendlyName(pX509));
} }
else throw OpenSSLException("PKCS12Container::load()"); else
{
sk_X509_pop_free(pCA, X509_free);
PKCS12_free(pPKCS12);
throw OpenSSLException("PKCS12Container::load()");
}
} }
sk_X509_pop_free(pCA, X509_free);
} }
} }
else else
{ {
PKCS12_free(pPKCS12);
throw OpenSSLException(); throw OpenSSLException();
} }
PKCS12_free(pPKCS12); PKCS12_free(pPKCS12);
sk_X509_pop_free(pCA, X509_free);
if (pCert) X509_free(pCert);
poco_assert_dbg (_caCertList.size() == _caCertNames.size()); poco_assert_dbg (_caCertList.size() == _caCertNames.size());
} }
else else