[PATCH] Remove potential reference count races

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


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

---
 dlls/shell32/shlmenu.c |   22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/dlls/shell32/shlmenu.c b/dlls/shell32/shlmenu.c
index 911feca..aceaf76 100644
--- a/dlls/shell32/shlmenu.c
+++ b/dlls/shell32/shlmenu.c
@@ -225,7 +225,7 @@ static int FM_InitMenuPopup(HMENU hmenu, LPCITEMIDLIST pAlternatePidl)
 		  TRACE("leave callback\n");
 		}
 
-		NumberOfItems++;
+		++NumberOfItems;
 	      }
 	      IEnumIDList_Release (lpe);
 	    }
@@ -238,7 +238,7 @@ static int FM_InitMenuPopup(HMENU hmenu, LPCITEMIDLIST pAlternatePidl)
 	{
           static const WCHAR szEmpty[] = { '(','e','m','p','t','y',')',0 };
 	  FileMenu_AppendItemW (hmenu, szEmpty, uID, FM_BLANK_ICON, 0, FM_DEFAULT_HEIGHT);
-	  NumberOfItems++;
+	  ++NumberOfItems;
 	}
 
 	menudata->bInitialized = TRUE;
@@ -685,7 +685,7 @@ BOOL WINAPI FileMenu_DeleteAllItems (HMENU hmenu)
 	mii.cbSize = sizeof(MENUITEMINFOW);
 	mii.fMask = MIIM_SUBMENU|MIIM_DATA;
 
-	for (i = 0; i < GetMenuItemCount( hmenu ); i++)
+	for (i = 0; i < GetMenuItemCount( hmenu ); ++i)
 	{ GetMenuItemInfoW(hmenu, i, TRUE, &mii );
 
 	  SHFree((LPFMINFO)mii.dwItemData);
@@ -896,7 +896,7 @@ UINT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAd
 
 
 	/* Go through the menu items and clone them*/
-	for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; nItem--)
+	for (nItem = GetMenuItemCount(hmSrc) - 1; nItem >= 0; --nItem)
 	{
 	  miiSrc.cbSize = sizeof(MENUITEMINFOW);
 	  miiSrc.fMask =  MIIM_STATE | MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_TYPE | MIIM_DATA;
@@ -1042,7 +1042,7 @@ static HRESULT CompositeCMenu_Constructor(IContextMenu **menus,UINT menu_count,
     }
     ret->refCount=0;
     memcpy(ret->menus,menus,menu_count*sizeof(IContextMenu*));
-    for(i=0;i<menu_count;i++)
+    for(i=0;i<menu_count;++i)
         IContextMenu_AddRef(menus[i]);
     return IContextMenu3_QueryInterface(&(ret->IContextMenu3_iface),riid,ppv);
 }
@@ -1050,7 +1050,7 @@ static HRESULT CompositeCMenu_Constructor(IContextMenu **menus,UINT menu_count,
 static void CompositeCMenu_Destroy(CompositeCMenu *This)
 {
     UINT i;
-    for(i=0;i<This->menu_count;i++)
+    for(i=0;i<This->menu_count;++i)
         IContextMenu_Release(This->menus[i]);
     HeapFree(GetProcessHeap(),0,This->menus);
     HeapFree(GetProcessHeap(),0,This->offsets);
@@ -1075,14 +1075,14 @@ static ULONG WINAPI CompositeCMenu_AddRef(IContextMenu3 *iface)
 {
     CompositeCMenu *This = impl_from_IContextMenu3(iface);
     TRACE("(%p)->()\n",iface);
-    return ++This->refCount;
+    return InterlockedIncrement(&This->refCount);
 }
 
 static ULONG WINAPI CompositeCMenu_Release(IContextMenu3 *iface)
 {
     CompositeCMenu *This = impl_from_IContextMenu3(iface);
     TRACE("(%p)->()\n",iface);
-    if(--This->refCount)
+    if(InterlockedDecrement(&This->refCount))
         return This->refCount;
     CompositeCMenu_Destroy(This);
     return 0;
@@ -1119,7 +1119,7 @@ static HRESULT WINAPI CompositeCMenu_InvokeCommand(IContextMenu3* iface,LPCMINVO
     {
         /*call each handler until one of them succeeds*/
         UINT i=0;
-        for(;i<This->menu_count;i++)
+        for(;i<This->menu_count;++i)
         {
             HRESULT hres;
             if(SUCCEEDED(hres=IContextMenu_InvokeCommand(This->menus[i],pici)))
@@ -1141,7 +1141,7 @@ static HRESULT WINAPI CompositeCMenu_QueryContextMenu(IContextMenu3 *iface, HMEN
     UINT i=0;
     UINT id_offset=idCmdFirst;
     TRACE("(%p)->(%p,%u,%u,%u,%x)\n",iface,hmenu,indexMenu,idCmdFirst,idCmdLast,uFlags);
-    for(;i<This->menu_count;i++)
+    for(;i<This->menu_count;++i)
     {
         HRESULT hres;
         This->offsets[i]=id_offset;
@@ -1212,7 +1212,7 @@ static HRESULT WINAPI CompositeCMenu_HandleMenuMsg2(IContextMenu3 *iface, UINT u
     case WM_MENUCHAR:
         {
             UINT i=0;
-            for(;i<This->menu_count;i++)
+            for(;i<This->menu_count;++i)
             {
                 hres = IContextMenu_QueryInterface(This->menus[i],&IID_IContextMenu3,(void**)&handler);
                 if(SUCCEEDED(hres))
-- 
1.7.7.6




More information about the wine-patches mailing list