crypt32: Use a structure to hold function address handle.

This commit is contained in:
Juan Lang 2007-10-17 09:30:33 -07:00 committed by Alexandre Julliard
parent 5bfd7044ea
commit 6b390b4009
1 changed files with 26 additions and 3 deletions

View File

@ -275,6 +275,11 @@ BOOL WINAPI CryptInstallOIDFunctionAddress(HMODULE hModule,
return ret; return ret;
} }
struct FuncAddr
{
HMODULE lib;
};
static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID, static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr) LPCSTR szFuncName, LPVOID *ppvFuncAddr, HCRYPTOIDFUNCADDR *phFuncAddr)
{ {
@ -322,10 +327,22 @@ static BOOL CRYPT_GetFuncFromReg(DWORD dwEncodingType, LPCSTR pszOID,
*ppvFuncAddr = GetProcAddress(lib, funcName); *ppvFuncAddr = GetProcAddress(lib, funcName);
if (*ppvFuncAddr) if (*ppvFuncAddr)
{ {
*phFuncAddr = (HCRYPTOIDFUNCADDR)lib; struct FuncAddr *addr =
CryptMemAlloc(sizeof(struct FuncAddr));
if (addr)
{
addr->lib = lib;
*phFuncAddr = addr;
ret = TRUE; ret = TRUE;
} }
else else
{
*phFuncAddr = NULL;
FreeLibrary(lib);
}
}
else
{ {
/* Unload the library, the caller doesn't want /* Unload the library, the caller doesn't want
* to unload it when the return value is NULL. * to unload it when the return value is NULL.
@ -409,7 +426,13 @@ BOOL WINAPI CryptFreeOIDFunctionAddress(HCRYPTOIDFUNCADDR hFuncAddr,
* and only unload it if it can be unloaded. Also need to implement ref * and only unload it if it can be unloaded. Also need to implement ref
* counting on the functions. * counting on the functions.
*/ */
FreeLibrary((HMODULE)hFuncAddr); if (hFuncAddr)
{
struct FuncAddr *addr = (struct FuncAddr *)hFuncAddr;
FreeLibrary(addr->lib);
CryptMemFree(addr);
}
return TRUE; return TRUE;
} }