Commit 917df923 authored by Kevin Koltzau's avatar Kevin Koltzau Committed by Alexandre Julliard

Prevent memory leak and superfluous status notifications.

parent adc86dcc
...@@ -1486,7 +1486,8 @@ lend: ...@@ -1486,7 +1486,8 @@ lend:
HINTERNET FTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName, HINTERNET FTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName,
INTERNET_PORT nServerPort, LPCWSTR lpszUserName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext) LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
DWORD dwInternalFlags)
{ {
struct sockaddr_in socketAddr; struct sockaddr_in socketAddr;
struct hostent *phe = NULL; struct hostent *phe = NULL;
...@@ -1567,6 +1568,7 @@ HINTERNET FTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName, ...@@ -1567,6 +1568,7 @@ HINTERNET FTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName,
lpwfs->hdr.htype = WH_HFTPSESSION; lpwfs->hdr.htype = WH_HFTPSESSION;
lpwfs->hdr.dwFlags = dwFlags; lpwfs->hdr.dwFlags = dwFlags;
lpwfs->hdr.dwContext = dwContext; lpwfs->hdr.dwContext = dwContext;
lpwfs->hdr.dwInternalFlags = dwInternalFlags;
lpwfs->hdr.lpwhparent = (LPWININETHANDLEHEADER)hInternet; lpwfs->hdr.lpwhparent = (LPWININETHANDLEHEADER)hInternet;
lpwfs->sndSocket = nsocket; lpwfs->sndSocket = nsocket;
lpwfs->download_in_progress = NULL; lpwfs->download_in_progress = NULL;
...@@ -1587,7 +1589,8 @@ HINTERNET FTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName, ...@@ -1587,7 +1589,8 @@ HINTERNET FTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName,
if (FTP_ConnectToHost(lpwfs)) if (FTP_ConnectToHost(lpwfs))
{ {
if (hIC->lpfnStatusCB) /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
if (hIC->lpfnStatusCB && !(lpwfs->hdr.dwInternalFlags & INET_OPENURL))
{ {
INTERNET_ASYNC_RESULT iar; INTERNET_ASYNC_RESULT iar;
...@@ -2499,6 +2502,7 @@ BOOL FTP_CloseFileTransferHandle(LPWININETFILE lpwh) ...@@ -2499,6 +2502,7 @@ BOOL FTP_CloseFileTransferHandle(LPWININETFILE lpwh)
{ {
LPWININETFTPSESSIONA lpwfs = (LPWININETFTPSESSIONA) lpwh->hdr.lpwhparent; LPWININETFTPSESSIONA lpwfs = (LPWININETFTPSESSIONA) lpwh->hdr.lpwhparent;
INT nResCode; INT nResCode;
HINTERNET handle;
TRACE("\n"); TRACE("\n");
...@@ -2517,7 +2521,15 @@ BOOL FTP_CloseFileTransferHandle(LPWININETFILE lpwh) ...@@ -2517,7 +2521,15 @@ BOOL FTP_CloseFileTransferHandle(LPWININETFILE lpwh)
close(lpwh->nDataSocket); close(lpwh->nDataSocket);
HeapFree(GetProcessHeap(), 0, lpwh); HeapFree(GetProcessHeap(), 0, lpwh);
/* If this handle was opened with InternetOpenUrl, we need to close the parent to prevent
a memory leek
*/
if(lpwfs->hdr.dwInternalFlags & INET_OPENURL)
{
handle = WININET_FindHandle( &lpwfs->hdr );
InternetCloseHandle(handle);
}
return TRUE; return TRUE;
} }
......
...@@ -1789,7 +1789,8 @@ lend: ...@@ -1789,7 +1789,8 @@ lend:
*/ */
HINTERNET HTTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName, HINTERNET HTTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName,
INTERNET_PORT nServerPort, LPCWSTR lpszUserName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext) LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
DWORD dwInternalFlags)
{ {
BOOL bSuccess = FALSE; BOOL bSuccess = FALSE;
LPWININETAPPINFOW hIC = NULL; LPWININETAPPINFOW hIC = NULL;
...@@ -1830,6 +1831,7 @@ HINTERNET HTTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName, ...@@ -1830,6 +1831,7 @@ HINTERNET HTTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName,
lpwhs->hdr.lpwhparent = &hIC->hdr; lpwhs->hdr.lpwhparent = &hIC->hdr;
lpwhs->hdr.dwFlags = dwFlags; lpwhs->hdr.dwFlags = dwFlags;
lpwhs->hdr.dwContext = dwContext; lpwhs->hdr.dwContext = dwContext;
lpwhs->hdr.dwInternalFlags = dwInternalFlags;
if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) { if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
if(strchrW(hIC->lpszProxy, ' ')) if(strchrW(hIC->lpszProxy, ' '))
FIXME("Several proxies not implemented.\n"); FIXME("Several proxies not implemented.\n");
...@@ -1842,7 +1844,8 @@ HINTERNET HTTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName, ...@@ -1842,7 +1844,8 @@ HINTERNET HTTP_Connect(HINTERNET hInternet, LPCWSTR lpszServerName,
lpwhs->lpszUserName = WININET_strdupW(lpszUserName); lpwhs->lpszUserName = WININET_strdupW(lpszUserName);
lpwhs->nServerPort = nServerPort; lpwhs->nServerPort = nServerPort;
if (hIC->lpfnStatusCB) /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
if (hIC->lpfnStatusCB && !(lpwhs->hdr.dwInternalFlags & INET_OPENURL))
{ {
INTERNET_ASYNC_RESULT iar; INTERNET_ASYNC_RESULT iar;
...@@ -2408,6 +2411,15 @@ void HTTP_CloseHTTPRequestHandle(LPWININETHTTPREQW lpwhr) ...@@ -2408,6 +2411,15 @@ void HTTP_CloseHTTPRequestHandle(LPWININETHTTPREQW lpwhr)
HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders); HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders);
HeapFree(GetProcessHeap(), 0, lpwhr); HeapFree(GetProcessHeap(), 0, lpwhr);
/* If this handle was opened with InternetOpenUrl, we need to close the parent to prevent
a memory leek
*/
if(lpwhs->hdr.dwInternalFlags & INET_OPENURL)
{
handle = WININET_FindHandle( &lpwhs->hdr );
InternetCloseHandle(handle);
}
} }
...@@ -2426,10 +2438,14 @@ void HTTP_CloseHTTPSessionHandle(LPWININETHTTPSESSIONW lpwhs) ...@@ -2426,10 +2438,14 @@ void HTTP_CloseHTTPSessionHandle(LPWININETHTTPSESSIONW lpwhs)
hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent; hIC = (LPWININETAPPINFOW) lpwhs->hdr.lpwhparent;
handle = WININET_FindHandle( &lpwhs->hdr ); /* Don't send a handle closing callback if this handle was created with InternetOpenUrl */
SendAsyncCallback(hIC, handle, lpwhs->hdr.dwContext, if(!(lpwhs->hdr.dwInternalFlags & INET_OPENURL))
INTERNET_STATUS_HANDLE_CLOSING, lpwhs, {
sizeof(HINTERNET)); handle = WININET_FindHandle( &lpwhs->hdr );
SendAsyncCallback(hIC, handle, lpwhs->hdr.dwContext,
INTERNET_STATUS_HANDLE_CLOSING, lpwhs,
sizeof(HINTERNET));
}
if (lpwhs->lpszServerName) if (lpwhs->lpszServerName)
HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
......
...@@ -665,12 +665,12 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet, ...@@ -665,12 +665,12 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
{ {
case INTERNET_SERVICE_FTP: case INTERNET_SERVICE_FTP:
rc = FTP_Connect(hInternet, lpszServerName, nServerPort, rc = FTP_Connect(hInternet, lpszServerName, nServerPort,
lpszUserName, lpszPassword, dwFlags, dwContext); lpszUserName, lpszPassword, dwFlags, dwContext, 0);
break; break;
case INTERNET_SERVICE_HTTP: case INTERNET_SERVICE_HTTP:
rc = HTTP_Connect(hInternet, lpszServerName, nServerPort, rc = HTTP_Connect(hInternet, lpszServerName, nServerPort,
lpszUserName, lpszPassword, dwFlags, dwContext); lpszUserName, lpszPassword, dwFlags, dwContext, 0);
break; break;
case INTERNET_SERVICE_GOPHER: case INTERNET_SERVICE_GOPHER:
...@@ -2069,8 +2069,8 @@ HINTERNET WINAPI INTERNET_InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl, ...@@ -2069,8 +2069,8 @@ HINTERNET WINAPI INTERNET_InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
case INTERNET_SCHEME_FTP: case INTERNET_SCHEME_FTP:
if(urlComponents.nPort == 0) if(urlComponents.nPort == 0)
urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT; urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT;
client = InternetConnectW(hInternet, hostName, urlComponents.nPort, client = FTP_Connect(hInternet, hostName, urlComponents.nPort,
userName, password, INTERNET_SERVICE_FTP, dwFlags, dwContext); userName, password, dwFlags, dwContext, INET_OPENURL);
client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext); client1 = FtpOpenFileW(client, path, GENERIC_READ, dwFlags, dwContext);
break; break;
...@@ -2084,8 +2084,8 @@ HINTERNET WINAPI INTERNET_InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl, ...@@ -2084,8 +2084,8 @@ HINTERNET WINAPI INTERNET_InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl,
else else
urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT; urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
} }
client = InternetConnectW(hInternet, hostName, urlComponents.nPort, userName, client = HTTP_Connect(hInternet, hostName, urlComponents.nPort,
password, INTERNET_SERVICE_HTTP, dwFlags, dwContext); userName, password, dwFlags, dwContext, INET_OPENURL);
if(client == NULL) if(client == NULL)
break; break;
client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext); client1 = HttpOpenRequestW(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext);
......
...@@ -81,12 +81,15 @@ typedef enum ...@@ -81,12 +81,15 @@ typedef enum
WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST, WH_HHTTPREQ = INTERNET_HANDLE_TYPE_HTTP_REQUEST,
} WH_TYPE; } WH_TYPE;
#define INET_OPENURL 0x0001
typedef struct _WININETHANDLEHEADER typedef struct _WININETHANDLEHEADER
{ {
WH_TYPE htype; WH_TYPE htype;
DWORD dwFlags; DWORD dwFlags;
DWORD dwContext; DWORD dwContext;
DWORD dwError; DWORD dwError;
DWORD dwInternalFlags;
struct _WININETHANDLEHEADER *lpwhparent; struct _WININETHANDLEHEADER *lpwhparent;
} WININETHANDLEHEADER, *LPWININETHANDLEHEADER; } WININETHANDLEHEADER, *LPWININETHANDLEHEADER;
...@@ -346,11 +349,13 @@ time_t ConvertTimeString(LPCWSTR asctime); ...@@ -346,11 +349,13 @@ time_t ConvertTimeString(LPCWSTR asctime);
HINTERNET FTP_Connect(HINTERNET hInterent, LPCWSTR lpszServerName, HINTERNET FTP_Connect(HINTERNET hInterent, LPCWSTR lpszServerName,
INTERNET_PORT nServerPort, LPCWSTR lpszUserName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext); LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
DWORD dwInternalFlags);
HINTERNET HTTP_Connect(HINTERNET hInterent, LPCWSTR lpszServerName, HINTERNET HTTP_Connect(HINTERNET hInterent, LPCWSTR lpszServerName,
INTERNET_PORT nServerPort, LPCWSTR lpszUserName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext); LPCWSTR lpszPassword, DWORD dwFlags, DWORD dwContext,
DWORD dwInternalFlags);
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort, BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
struct hostent **phe, struct sockaddr_in *psa); struct hostent **phe, struct sockaddr_in *psa);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment