crypt32(2/13): Propagate errors from CertFree*Context to CertDelete*FromStore

View: New views
1 Messages — Rating Filter:   Alert me  

crypt32(2/13): Propagate errors from CertFree*Context to CertDelete*FromStore

by Juan Lang-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This adds a todo_wine to a test which succeeded almost by accident
before:  the reference count had become negative on the already freed
certificate context.  The todo_wine is removed toward the end of this
series.
--Juan

[0002-Propagate-errors-from-CertFree-Context-to-CertDelete.patch]

From 3aa6ca547e1ac621b484a1472a628d6d0c303220 Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang@...>
Date: Fri, 30 Oct 2009 15:18:53 -0700
Subject: [PATCH] Propagate errors from CertFree*Context to CertDelete*FromStore

---
 dlls/crypt32/ctl.c         |    8 +++-----
 dlls/crypt32/store.c       |   15 +++++----------
 dlls/crypt32/tests/store.c |    1 +
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/dlls/crypt32/ctl.c b/dlls/crypt32/ctl.c
index e2511fa..44b517a 100644
--- a/dlls/crypt32/ctl.c
+++ b/dlls/crypt32/ctl.c
@@ -309,10 +309,7 @@ BOOL WINAPI CertDeleteCTLFromStore(PCCTL_CONTEXT pCtlContext)
     if (!pCtlContext)
         ret = TRUE;
     else if (!pCtlContext->hCertStore)
-    {
-        ret = TRUE;
-        CertFreeCTLContext(pCtlContext);
-    }
+        ret = CertFreeCTLContext(pCtlContext);
     else
     {
         PWINECRYPT_CERTSTORE hcs = pCtlContext->hCertStore;
@@ -321,7 +318,8 @@ BOOL WINAPI CertDeleteCTLFromStore(PCCTL_CONTEXT pCtlContext)
             ret = FALSE;
         else
             ret = hcs->ctls.deleteContext(hcs, (void *)pCtlContext);
-        CertFreeCTLContext(pCtlContext);
+        if (ret)
+            ret = CertFreeCTLContext(pCtlContext);
     }
     return ret;
 }
diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c
index 8acc6f6..a529ac6 100644
--- a/dlls/crypt32/store.c
+++ b/dlls/crypt32/store.c
@@ -966,10 +966,7 @@ BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
     if (!pCertContext)
         ret = TRUE;
     else if (!pCertContext->hCertStore)
-    {
-        ret = TRUE;
-        CertFreeCertificateContext(pCertContext);
-    }
+        ret = CertFreeCertificateContext(pCertContext);
     else
     {
         PWINECRYPT_CERTSTORE hcs = pCertContext->hCertStore;
@@ -979,7 +976,7 @@ BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
         else
             ret = hcs->certs.deleteContext(hcs, (void *)pCertContext);
         if (ret)
-            CertFreeCertificateContext(pCertContext);
+            ret = CertFreeCertificateContext(pCertContext);
     }
     return ret;
 }
@@ -1105,10 +1102,7 @@ BOOL WINAPI CertDeleteCRLFromStore(PCCRL_CONTEXT pCrlContext)
     if (!pCrlContext)
         ret = TRUE;
     else if (!pCrlContext->hCertStore)
-    {
-        ret = TRUE;
-        CertFreeCRLContext(pCrlContext);
-    }
+        ret = CertFreeCRLContext(pCrlContext);
     else
     {
         PWINECRYPT_CERTSTORE hcs = pCrlContext->hCertStore;
@@ -1117,7 +1111,8 @@ BOOL WINAPI CertDeleteCRLFromStore(PCCRL_CONTEXT pCrlContext)
             ret = FALSE;
         else
             ret = hcs->crls.deleteContext(hcs, (void *)pCrlContext);
-        CertFreeCRLContext(pCrlContext);
+        if (ret)
+            ret = CertFreeCRLContext(pCrlContext);
     }
     return ret;
 }
diff --git a/dlls/crypt32/tests/store.c b/dlls/crypt32/tests/store.c
index ae10fbc..88f53ed 100644
--- a/dlls/crypt32/tests/store.c
+++ b/dlls/crypt32/tests/store.c
@@ -237,6 +237,7 @@ static void testMemStore(void)
          GetLastError());
         /* try deleting a copy */
         ret = CertDeleteCertificateFromStore(copy);
+        todo_wine
         ok(ret, "CertDeleteCertificateFromStore failed: %08x\n",
          GetLastError());
         /* check that the store is empty */
--
1.6.0.6