Schannel: Use smart-ptr to manage the certiticate context

We already have the alias for it, we just never updated the stored
member to use it.

Pick-to: 6.10 6.9 6.8
Change-Id: I850c9f0b899a15603b4c5ac83693019b856effb2
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Mårten Nordheim 2025-06-02 10:52:59 +02:00
parent 6c18b438a3
commit f9fbdba3a1
2 changed files with 4 additions and 8 deletions

View File

@ -16,11 +16,7 @@ namespace QTlsPrivate {
X509CertificateSchannel::X509CertificateSchannel() = default;
X509CertificateSchannel::~X509CertificateSchannel()
{
if (certificateContext)
CertFreeCertificateContext(certificateContext);
}
X509CertificateSchannel::~X509CertificateSchannel() = default;
TlsKey *X509CertificateSchannel::publicKey() const
{
@ -33,7 +29,7 @@ TlsKey *X509CertificateSchannel::publicKey() const
Qt::HANDLE X509CertificateSchannel::handle() const
{
return Qt::HANDLE(certificateContext);
return Qt::HANDLE(certificateContext.get());
}
QSslCertificate X509CertificateSchannel::QSslCertificate_from_CERT_CONTEXT(const CERT_CONTEXT *certificateContext)
@ -44,7 +40,7 @@ QSslCertificate X509CertificateSchannel::QSslCertificate_from_CERT_CONTEXT(const
if (!certificate.isNull()) {
auto *certBackend = QTlsBackend::backend<X509CertificateSchannel>(certificate);
Q_ASSERT(certBackend);
certBackend->certificateContext = CertDuplicateCertificateContext(certificateContext);
certBackend->certificateContext.reset(CertDuplicateCertificateContext(certificateContext));
}
return certificate;
}

View File

@ -41,7 +41,7 @@ public:
QList<QSslCertificate> *caCertificates,
const QByteArray &passPhrase);
private:
const CERT_CONTEXT *certificateContext = nullptr;
QPCCertContextPointer certificateContext;
Q_DISABLE_COPY_MOVE(X509CertificateSchannel);
};