diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c index 14acceb1000..f49a4973d7b 100644 --- a/dlls/advapi32/crypt.c +++ b/dlls/advapi32/crypt.c @@ -636,7 +636,7 @@ BOOL WINAPI CryptContextAddRef (HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFl return FALSE; } - pProv->refcount++; + InterlockedIncrement(&pProv->refcount); return TRUE; } @@ -672,8 +672,7 @@ BOOL WINAPI CryptReleaseContext (HCRYPTPROV hProv, DWORD dwFlags) return FALSE; } - pProv->refcount--; - if (pProv->refcount <= 0) + if (InterlockedDecrement(&pProv->refcount) == 0) { ret = pProv->pFuncs->pCPReleaseContext(pProv->hPrivate, dwFlags); pProv->dwMagic = 0; diff --git a/dlls/advapi32/crypt.h b/dlls/advapi32/crypt.h index afee3e2e29a..a4429642d24 100644 --- a/dlls/advapi32/crypt.h +++ b/dlls/advapi32/crypt.h @@ -63,7 +63,7 @@ typedef struct tagPROVFUNCS typedef struct tagCRYPTPROV { DWORD dwMagic; - UINT refcount; + LONG refcount; HMODULE hModule; PPROVFUNCS pFuncs; HCRYPTPROV hPrivate; /*CSP's handle - Should not be given to application under any circumstances!*/