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

Alexandre Julliard julliard at wine.codeweavers.com
Thu Apr 20 08:45:59 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: d133ff9afb07c2e2516efc411cccc00c833a1c58
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=d133ff9afb07c2e2516efc411cccc00c833a1c58

Author: Robert Shearman <rob at codeweavers.com>
Date:   Thu Apr 20 11:46:38 2006 +0100

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.

---

 dlls/wininet/internet.c |   51 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 36 insertions(+), 15 deletions(-)

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




More information about the wine-cvs mailing list