crypt32(5/13): When add-ref'ing a context, add-ref its linked contexts too

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

crypt32(5/13): When add-ref'ing a context, add-ref its linked contexts too

by Juan Lang-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--Juan

[0005-When-add-ref-ing-a-context-add-ref-its-linked-conte.patch]

From 2fdb4817df3b82db63531526a9d7f48dc3527433 Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang@...>
Date: Fri, 30 Oct 2009 17:25:28 -0700
Subject: [PATCH] When add-ref'ing a context, add-ref its linked contexts too

---
 dlls/crypt32/context.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/context.c b/dlls/crypt32/context.c
index 20fe024..4d325c1 100644
--- a/dlls/crypt32/context.c
+++ b/dlls/crypt32/context.c
@@ -106,6 +106,34 @@ void Context_AddRef(void *context, size_t contextSize)
     PBASE_CONTEXT baseContext = BASE_CONTEXT_FROM_CONTEXT(context, contextSize);
 
     InterlockedIncrement(&baseContext->ref);
+    if (baseContext->type == ContextTypeLink)
+    {
+        void *linkedContext = Context_GetLinkedContext(context, contextSize);
+        PBASE_CONTEXT linkedBase = BASE_CONTEXT_FROM_CONTEXT(linkedContext,
+         contextSize);
+
+        /* Add-ref the linked contexts too */
+        while (linkedContext && linkedBase->type == ContextTypeLink)
+        {
+            InterlockedIncrement(&linkedBase->ref);
+            linkedContext = Context_GetLinkedContext(linkedContext,
+             contextSize);
+            if (linkedContext)
+                linkedBase = BASE_CONTEXT_FROM_CONTEXT(linkedContext,
+                 contextSize);
+            else
+                linkedBase = NULL;
+        }
+        if (linkedContext)
+        {
+            /* It's not a link context, so it wasn't add-ref'ed in the while
+             * loop, so add-ref it here.
+             */
+            linkedBase = BASE_CONTEXT_FROM_CONTEXT(linkedContext,
+             contextSize);
+            InterlockedIncrement(&linkedBase->ref);
+        }
+    }
 }
 
 void *Context_GetExtra(const void *context, size_t contextSize)
--
1.6.0.6