From 92f098e83fae191f0dd97d1fdc212cf4b64dc9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Mon, 2 Jun 2025 10:52:59 +0200 Subject: [PATCH] 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.8 Change-Id: I850c9f0b899a15603b4c5ac83693019b856effb2 Reviewed-by: Edward Welbourne (cherry picked from commit f9fbdba3a1d8cc40681f3df5fcccc05a76b5211e) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 00ecb3b6f5a80bdf37997a85fb8f42a0230c643a) --- src/plugins/tls/schannel/qx509_schannel.cpp | 10 +++------- src/plugins/tls/schannel/qx509_schannel_p.h | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/plugins/tls/schannel/qx509_schannel.cpp b/src/plugins/tls/schannel/qx509_schannel.cpp index d9d82dce29f..283d1f4af53 100644 --- a/src/plugins/tls/schannel/qx509_schannel.cpp +++ b/src/plugins/tls/schannel/qx509_schannel.cpp @@ -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(certificate); Q_ASSERT(certBackend); - certBackend->certificateContext = CertDuplicateCertificateContext(certificateContext); + certBackend->certificateContext.reset(CertDuplicateCertificateContext(certificateContext)); } return certificate; } diff --git a/src/plugins/tls/schannel/qx509_schannel_p.h b/src/plugins/tls/schannel/qx509_schannel_p.h index 4625c9584cc..caf2a914f65 100644 --- a/src/plugins/tls/schannel/qx509_schannel_p.h +++ b/src/plugins/tls/schannel/qx509_schannel_p.h @@ -41,7 +41,7 @@ public: QList *caCertificates, const QByteArray &passPhrase); private: - const CERT_CONTEXT *certificateContext = nullptr; + QPCCertContextPointer certificateContext; Q_DISABLE_COPY_MOVE(X509CertificateSchannel); };