[PATCH 1/5] crypt32/tests: Fix some memory leaks (Valgrind).

Sven Baars sbaars at codeweavers.com
Fri Feb 18 14:56:12 CST 2022


Signed-off-by: Sven Baars <sbaars at codeweavers.com>
---
 dlls/crypt32/tests/cert.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c
index b96f94cc662..f0750cfc826 100644
--- a/dlls/crypt32/tests/cert.c
+++ b/dlls/crypt32/tests/cert.c
@@ -205,10 +205,9 @@ static void testAddCert(void)
     {
         CRYPT_DATA_BLOB hash = { sizeof(bigCert2Hash), bigCert2Hash };
 
-        /* Duplicate (AddRef) the context so we can still use it after
-         * deleting it from the store.
-         */
-        CertDuplicateCertificateContext(context);
+        /* We always need to call CertFreeCertificateContext after calling
+           CertAddEncodedCertificateToStore, which means that we can use
+           the context after deleting it from the store */
         CertDeleteCertificateFromStore(context);
         /* Set the same hash as bigCert2, and try to readd it */
         ret = CertSetCertificateContextProperty(context, CERT_HASH_PROP_ID,
@@ -243,10 +242,9 @@ static void testAddCert(void)
     ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
      bigCert2WithDifferentSerial, sizeof(bigCert2WithDifferentSerial),
      CERT_STORE_ADD_NEW, &context);
-    ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
-     GetLastError());
-    if (context)
-        CertDeleteCertificateFromStore(context);
+    ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
+    CertDeleteCertificateFromStore(context);
+    CertFreeCertificateContext(context);
 
     /* Adding a cert with the same subject name and serial number (but
      * different issuer) as an existing cert succeeds.
@@ -255,10 +253,9 @@ static void testAddCert(void)
     ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
      bigCertWithDifferentSubject, sizeof(bigCertWithDifferentSubject),
      CERT_STORE_ADD_NEW, &context);
-    ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
-     GetLastError());
-    if (context)
-        CertDeleteCertificateFromStore(context);
+    ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
+    CertDeleteCertificateFromStore(context);
+    CertFreeCertificateContext(context);
 
     /* Adding a cert with the same issuer name and serial number (but
      * different otherwise) as an existing cert succeeds.
@@ -267,10 +264,9 @@ static void testAddCert(void)
     ret = CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING,
      bigCertWithDifferentIssuer, sizeof(bigCertWithDifferentIssuer),
      CERT_STORE_ADD_NEW, &context);
-    ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n",
-     GetLastError());
-    if (context)
-        CertDeleteCertificateFromStore(context);
+    ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
+    CertDeleteCertificateFromStore(context);
+    CertFreeCertificateContext(context);
 
     collection = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
      CERT_STORE_CREATE_NEW_FLAG, NULL);
@@ -4318,6 +4314,7 @@ static void test_VerifySignature(void)
     BCryptDestroyHash(bhash);
 done:
     BCryptCloseAlgorithmProvider(alg, 0);
+    BCryptDestroyKey(bkey);
 
     LocalFree(info);
     CertFreeCertificateContext(cert);
-- 
2.30.0.335.ge6362826a0




More information about the wine-devel mailing list