[PATCH] Remove potential reference count races

max at mtew.isa-geek.net max at mtew.isa-geek.net
Sat Oct 27 20:59:31 CDT 2012


From: Max TenEyck Woodbury <max at mtew.isa-geek.net>

---
 dlls/ole32/stubmanager.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/dlls/ole32/stubmanager.c b/dlls/ole32/stubmanager.c
index e7018b9..14b4901 100644
--- a/dlls/ole32/stubmanager.c
+++ b/dlls/ole32/stubmanager.c
@@ -104,7 +104,7 @@ struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *s
     EnterCriticalSection(&m->lock);
     list_add_head(&m->ifstubs, &stub->entry);
     /* every normal marshal is counted so we don't allow more than we should */
-    if (flags & MSHLFLAGS_NORMAL) m->norm_refs++;
+    if (flags & MSHLFLAGS_NORMAL) ++m->norm_refs;
     LeaveCriticalSection(&m->lock);
 
     TRACE("ifstub %p created with ipid %s\n", stub, debugstr_guid(&stub->ipid));
@@ -257,7 +257,7 @@ static ULONG stub_manager_int_addref(struct stub_manager *This)
     ULONG refs;
 
     EnterCriticalSection(&This->apt->cs);
-    refs = ++This->refs;
+    refs = InterlockedIncrement(&This->refs);
     LeaveCriticalSection(&This->apt->cs);
 
     TRACE("before %d\n", refs - 1);
@@ -272,7 +272,7 @@ ULONG stub_manager_int_release(struct stub_manager *This)
     APARTMENT *apt = This->apt;
 
     EnterCriticalSection(&apt->cs);
-    refs = --This->refs;
+    refs = InterlockedDecrement(&This->refs);
 
     TRACE("after %d\n", refs);
 
@@ -528,7 +528,7 @@ BOOL stub_manager_notify_unmarshal(struct stub_manager *m, const IPID *ipid)
     if (ifstub->flags & MSHLFLAGS_NORMAL)
     {
         if (m->norm_refs)
-            m->norm_refs--;
+            --m->norm_refs;
         else
         {
             ERR("attempted invalid normal unmarshal, norm_refs is zero\n");
@@ -664,12 +664,12 @@ static HRESULT WINAPI RemUnknown_RemQueryInterface(IRemUnknown *iface,
 
     *ppQIResults = CoTaskMemAlloc(sizeof(REMQIRESULT) * cIids);
 
-    for (i = 0; i < cIids; i++)
+    for (i = 0; i < cIids; ++i)
     {
         HRESULT hrobj = marshal_object(apt, &(*ppQIResults)[i].std, &iids[i],
                                        stubmgr->object, MSHCTX_DIFFERENTMACHINE, NULL, MSHLFLAGS_NORMAL);
         if (hrobj == S_OK)
-            successful_qis++;
+            ++successful_qis;
         (*ppQIResults)[i].hResult = hrobj;
     }
 
@@ -694,7 +694,7 @@ static HRESULT WINAPI RemUnknown_RemAddRef(IRemUnknown *iface,
 
     TRACE("(%p)->(%d, %p, %p)\n", iface, cInterfaceRefs, InterfaceRefs, pResults);
 
-    for (i = 0; i < cInterfaceRefs; i++)
+    for (i = 0; i < cInterfaceRefs; ++i)
     {
         APARTMENT *apt;
         struct stub_manager *stubmgr;
@@ -726,7 +726,7 @@ static HRESULT WINAPI RemUnknown_RemRelease(IRemUnknown *iface,
 
     TRACE("(%p)->(%d, %p)\n", iface, cInterfaceRefs, InterfaceRefs);
 
-    for (i = 0; i < cInterfaceRefs; i++)
+    for (i = 0; i < cInterfaceRefs; ++i)
     {
         APARTMENT *apt;
         struct stub_manager *stubmgr;
-- 
1.7.7.6




More information about the wine-patches mailing list