[PATCH] Remove potential reference count races
max at mtew.isa-geek.net
max at mtew.isa-geek.net
Sat Oct 27 20:59:25 CDT 2012
From: Max TenEyck Woodbury <max at mtew.isa-geek.net>
---
dlls/localspl/provider.c | 32 ++++++++++++++++----------------
1 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/dlls/localspl/provider.c b/dlls/localspl/provider.c
index 0c12a0e..e007051 100644
--- a/dlls/localspl/provider.c
+++ b/dlls/localspl/provider.c
@@ -309,7 +309,7 @@ static LPCWSTR get_basename_from_name(LPCWSTR name)
if ((name) && (name[1])) {
/* found a separator ('\') followed by a name:
skip over the separator and return the rest */
- name++;
+ ++name;
}
else
{
@@ -333,7 +333,7 @@ static void monitor_unload(monitor_t * pm)
EnterCriticalSection(&monitor_handles_cs);
- if (pm->refcount) pm->refcount--;
+ if (pm->refcount) InterlockedDecrement(&pm->refcount);
if (pm->refcount == 0) {
list_remove(&pm->entry);
@@ -408,7 +408,7 @@ static monitor_t * monitor_load(LPCWSTR name, LPWSTR dllname)
if (pm == NULL) goto cleanup;
list_add_tail(&monitor_handles, &pm->entry);
}
- pm->refcount++;
+ InterlockedIncrement(&pm->refcount);
if (pm->name == NULL) {
/* Load the monitor */
@@ -516,7 +516,7 @@ static monitor_t * monitor_load(LPCWSTR name, LPWSTR dllname)
}
cleanup:
if ((pm_localport == NULL) && (pm != NULL) && (lstrcmpW(pm->name, localportW) == 0)) {
- pm->refcount++;
+ InterlockedIncrement(&pm->refcount);
pm_localport = pm;
}
LeaveCriticalSection(&monitor_handles_cs);
@@ -551,8 +551,8 @@ static DWORD monitor_loadall(void)
buffer[0] = '\0';
RegEnumKeyW(hmonitors, id, buffer, MAX_PATH);
pm = monitor_load(buffer, NULL);
- if (pm) loaded++;
- id++;
+ if (pm) ++loaded;
+ ++id;
}
RegCloseKey(hmonitors);
}
@@ -581,7 +581,7 @@ static monitor_t * monitor_loadui(monitor_t * pm)
/* Try the Portmonitor first; works for many monitors */
if (pm->monitorUI) {
EnterCriticalSection(&monitor_handles_cs);
- pm->refcount++;
+ InterlockedIncrement(&pm->refcount);
LeaveCriticalSection(&monitor_handles_cs);
return pm;
}
@@ -651,7 +651,7 @@ static monitor_t * monitor_load_by_port(LPCWSTR portname)
buffer[len] = '\0'; /* use only the Monitor-Name */
pm = monitor_load(buffer, NULL);
}
- id++;
+ ++id;
}
LeaveCriticalSection(&monitor_handles_cs);
RegCloseKey(hroot);
@@ -702,7 +702,7 @@ static const printenv_t * validate_envW(LPCWSTR env)
TRACE("(%s)\n", debugstr_w(env));
if (env && env[0])
{
- for (i = 0; i < sizeof(all_printenv)/sizeof(all_printenv[0]); i++)
+ for (i = 0; i < sizeof(all_printenv)/sizeof(all_printenv[0]); ++i)
{
if (lstrcmpiW(env, all_printenv[i]->envname) == 0)
{
@@ -781,7 +781,7 @@ static DWORD get_local_monitors(DWORD level, LPBYTE pMonitors, DWORD cbBuf, LPDW
/* Windows returns only Port-Monitors here, but to simplify our code,
we do no filtering for Language-Monitors */
if (dllname[0]) {
- numentries++;
+ ++numentries;
needed += entrysize;
needed += (len+1) * sizeof(WCHAR); /* len is lstrlenW(monitorname) */
if (level > 1) {
@@ -810,7 +810,7 @@ static DWORD get_local_monitors(DWORD level, LPBYTE pMonitors, DWORD cbBuf, LPDW
}
}
}
- index++;
+ ++index;
len = sizeof(buffer)/sizeof(buffer[0]);
buffer[0] = '\0';
}
@@ -852,7 +852,7 @@ static DWORD get_local_printprocessors(LPWSTR regpathW, LPBYTE pPPInfo, DWORD cb
if (RegCreateKeyW(HKEY_LOCAL_MACHINE, regpathW, &hroot) == ERROR_SUCCESS) {
/* add "winprint" first */
- numentries++;
+ ++numentries;
needed = sizeof(PRINTPROCESSOR_INFO_1W) + sizeof(winprintW);
if (pPPInfo && (cbBuf >= needed)){
ppi = (PPRINTPROCESSOR_INFO_1W) pPPInfo;
@@ -881,7 +881,7 @@ static DWORD get_local_printprocessors(LPWSTR regpathW, LPBYTE pPPInfo, DWORD cb
}
if (dllname[0]) {
- numentries++;
+ ++numentries;
needed += sizeof(PRINTPROCESSOR_INFO_1W);
needed += (len+1) * sizeof(WCHAR); /* len is lstrlenW(printprocessor name) */
@@ -896,7 +896,7 @@ static DWORD get_local_printprocessors(LPWSTR regpathW, LPBYTE pPPInfo, DWORD cb
ptr += (len+1); /* len is lstrlenW(printprosessor name) */
}
}
- index++;
+ ++index;
len = sizeof(buffer)/sizeof(buffer[0]);
buffer[0] = '\0';
}
@@ -981,8 +981,8 @@ static DWORD get_ports_from_all_monitors(DWORD level, LPBYTE pPorts, DWORD cbBuf
out->fPortType = cache->fPortType;
out->Reserved = cache->Reserved;
}
- pi_index++;
- outindex++;
+ ++pi_index;
+ ++outindex;
}
}
}
--
1.7.7.6
More information about the wine-patches
mailing list