Module: wine Branch: master Commit: 59f2e837eb6cc4428a0048fd3b46830b9086af8f URL: http://source.winehq.org/git/wine.git/?a=commit;h=59f2e837eb6cc4428a0048fd3b...
Author: Jacek Caban jacek@codeweavers.com Date: Mon May 2 11:26:10 2011 +0200
wininet: Allocate buffer for host name in HTTP_HttpOpenRequestW only if needed.
---
dlls/wininet/http.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index fb01e36..bc1fcf4 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -2792,8 +2792,6 @@ static DWORD HTTP_HttpOpenRequestW(http_session_t *session, { appinfo_t *hIC = NULL; http_request_t *request; - LPWSTR lpszHostName = NULL; - static const WCHAR szHostForm[] = {'%','s',':','%','u',0}; DWORD len, res;
TRACE("-->\n"); @@ -2819,13 +2817,6 @@ static DWORD HTTP_HttpOpenRequestW(http_session_t *session, request->session = session; list_add_head( &session->hdr.children, &request->hdr.entry );
- lpszHostName = heap_alloc(sizeof(WCHAR) * (strlenW(session->hostName) + 7 /* length of ":65535" + 1 */)); - if (NULL == lpszHostName) - { - res = ERROR_OUTOFMEMORY; - goto lend; - } - if ((res = NETCON_init(&request->netConnection, dwFlags & INTERNET_FLAG_SECURE)) != ERROR_SUCCESS) goto lend; if (dwFlags & INTERNET_FLAG_IGNORE_CERT_CN_INVALID) @@ -2877,9 +2868,19 @@ static DWORD HTTP_HttpOpenRequestW(http_session_t *session, session->hostPort != INTERNET_DEFAULT_HTTP_PORT && session->hostPort != INTERNET_DEFAULT_HTTPS_PORT) { - sprintfW(lpszHostName, szHostForm, session->hostName, session->hostPort); - HTTP_ProcessHeader(request, hostW, lpszHostName, - HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ); + WCHAR *host_name; + + static const WCHAR host_formatW[] = {'%','s',':','%','u',0}; + + host_name = heap_alloc((strlenW(session->hostName) + 7 /* length of ":65535" + 1 */) * sizeof(WCHAR)); + if (!host_name) { + res = ERROR_OUTOFMEMORY; + goto lend; + } + + sprintfW(host_name, host_formatW, session->hostName, session->hostPort); + HTTP_ProcessHeader(request, hostW, host_name, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ); + heap_free(host_name); } else HTTP_ProcessHeader(request, hostW, session->hostName, @@ -2905,7 +2906,6 @@ static DWORD HTTP_HttpOpenRequestW(http_session_t *session, lend: TRACE("<-- %u (%p)\n", res, request);
- HeapFree(GetProcessHeap(), 0, lpszHostName); if(res != ERROR_SUCCESS) { WININET_Release( &request->hdr ); *ret = NULL;