wininet: Don't allocate memory for the thread error structure until it is needed.

Don't allocate memory for the thread error structure until it is
needed, as it is quite large and wastes memory for threads that don't
call any wininet function.
oldstable
Robert Shearman 2006-04-20 11:46:38 +01:00 committed by Alexandre Julliard
parent 0ced865aa1
commit d133ff9afb
1 changed files with 36 additions and 15 deletions

View File

@ -283,13 +283,6 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
WININET_hModule = (HMODULE)hinstDLL; WININET_hModule = (HMODULE)hinstDLL;
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
{
LPWITHREADERROR lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(WITHREADERROR));
if (NULL == lpwite)
return FALSE;
TlsSetValue(g_dwTlsErrIndex, (LPVOID)lpwite);
}
break; break;
case DLL_THREAD_DETACH: case DLL_THREAD_DETACH:
@ -651,14 +644,22 @@ BOOL WINAPI InternetGetLastResponseInfoA(LPDWORD lpdwError,
TRACE("\n"); TRACE("\n");
*lpdwError = lpwite->dwError; if (lpwite)
if (lpwite->dwError)
{ {
memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength); *lpdwError = lpwite->dwError;
*lpdwBufferLength = strlen(lpszBuffer); if (lpwite->dwError)
{
memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
*lpdwBufferLength = strlen(lpszBuffer);
}
else
*lpdwBufferLength = 0;
} }
else else
{
*lpdwError = 0;
*lpdwBufferLength = 0; *lpdwBufferLength = 0;
}
return TRUE; return TRUE;
} }
@ -680,14 +681,22 @@ BOOL WINAPI InternetGetLastResponseInfoW(LPDWORD lpdwError,
TRACE("\n"); TRACE("\n");
*lpdwError = lpwite->dwError; if (lpwite)
if (lpwite->dwError)
{ {
memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength); *lpdwError = lpwite->dwError;
*lpdwBufferLength = lstrlenW(lpszBuffer); if (lpwite->dwError)
{
memcpy(lpszBuffer, lpwite->response, *lpdwBufferLength);
*lpdwBufferLength = lstrlenW(lpszBuffer);
}
else
*lpdwBufferLength = 0;
} }
else else
{
*lpdwError = 0;
*lpdwBufferLength = 0; *lpdwBufferLength = 0;
}
return TRUE; return TRUE;
} }
@ -3048,6 +3057,12 @@ void INTERNET_SetLastError(DWORD dwError)
{ {
LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex); LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
if (!lpwite)
{
lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
TlsSetValue(g_dwTlsErrIndex, lpwite);
}
SetLastError(dwError); SetLastError(dwError);
if(lpwite) if(lpwite)
lpwite->dwError = dwError; lpwite->dwError = dwError;
@ -3065,6 +3080,7 @@ void INTERNET_SetLastError(DWORD dwError)
DWORD INTERNET_GetLastError(void) DWORD INTERNET_GetLastError(void)
{ {
LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex); LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
if (!lpwite) return 0;
/* TlsGetValue clears last error, so set it again here */ /* TlsGetValue clears last error, so set it again here */
SetLastError(lpwite->dwError); SetLastError(lpwite->dwError);
return lpwite->dwError; return lpwite->dwError;
@ -3476,6 +3492,11 @@ static VOID INTERNET_ExecuteWork(void)
LPSTR INTERNET_GetResponseBuffer(void) LPSTR INTERNET_GetResponseBuffer(void)
{ {
LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex); LPWITHREADERROR lpwite = (LPWITHREADERROR)TlsGetValue(g_dwTlsErrIndex);
if (!lpwite)
{
lpwite = HeapAlloc(GetProcessHeap(), 0, sizeof(*lpwite));
TlsSetValue(g_dwTlsErrIndex, lpwite);
}
TRACE("\n"); TRACE("\n");
return lpwite->response; return lpwite->response;
} }