From 728e5fa55966987c3a2fdc96d8890987eb7b7e9d Mon Sep 17 00:00:00 2001 From: Misha Koshelev Date: Thu, 20 Sep 2007 20:59:40 -0500 Subject: [PATCH] wininet: Track child handles, free all child handles on WININET_FreeHandle as native. --- dlls/wininet/cookie.c | 2 -- dlls/wininet/ftp.c | 3 +++ dlls/wininet/http.c | 2 ++ dlls/wininet/internet.c | 15 ++++++++++++++- dlls/wininet/internet.h | 3 +++ dlls/wininet/urlcache.c | 1 - 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c index b479aa7372c..abf897a4bf4 100644 --- a/dlls/wininet/cookie.c +++ b/dlls/wininet/cookie.c @@ -39,8 +39,6 @@ #include "wine/debug.h" #include "internet.h" -#include "wine/list.h" - #define RESPONSE_TIMEOUT 30 /* FROM internet.c */ diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c index 901f0a2e918..805ab44a262 100644 --- a/dlls/wininet/ftp.c +++ b/dlls/wininet/ftp.c @@ -1128,6 +1128,7 @@ HINTERNET FTP_FtpOpenFileW(LPWININETFTPSESSIONW lpwfs, WININET_AddRef( &lpwfs->hdr ); lpwh->lpFtpSession = lpwfs; + list_add_head( &lpwfs->hdr.children, &lpwh->hdr.entry ); handle = WININET_AllocHandle( &lpwh->hdr ); if( !handle ) @@ -1904,6 +1905,7 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, WININET_AddRef( &hIC->hdr ); lpwfs->lpAppInfo = hIC; + list_add_head( &hIC->hdr.children, &lpwfs->hdr.entry ); handle = WININET_AllocHandle( &lpwfs->hdr ); if( !handle ) @@ -3012,6 +3014,7 @@ static HINTERNET FTP_ReceiveFileList(LPWININETFTPSESSIONW lpwfs, INT nSocket, LP WININET_AddRef( &lpwfs->hdr ); lpwfn->lpFtpSession = lpwfs; + list_add_head( &lpwfs->hdr.children, &lpwfn->hdr.entry ); handle = WININET_AllocHandle( &lpwfn->hdr ); } diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index c1b8864343b..454d332989d 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -1371,6 +1371,7 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs, WININET_AddRef( &lpwhs->hdr ); lpwhr->lpHttpSession = lpwhs; + list_add_head( &lpwhs->hdr.children, &lpwhr->hdr.entry ); handle = WININET_AllocHandle( &lpwhr->hdr ); if (NULL == handle) @@ -2824,6 +2825,7 @@ HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, WININET_AddRef( &hIC->hdr ); lpwhs->lpAppInfo = hIC; + list_add_head( &hIC->hdr.children, &lpwhs->hdr.entry ); handle = WININET_AllocHandle( &lpwhs->hdr ); if (NULL == handle) diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 345b2aa59ad..5e95a122cb3 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -105,6 +105,8 @@ HINTERNET WININET_AllocHandle( LPWININETHANDLEHEADER info ) LPWININETHANDLEHEADER *p; UINT handle = 0, num; + list_init( &info->children ); + EnterCriticalSection( &WININET_cs ); if( !WININET_dwMaxHandles ) { @@ -182,6 +184,8 @@ BOOL WININET_Release( LPWININETHANDLEHEADER info ) INTERNET_STATUS_HANDLE_CLOSING, &info->hInternet, sizeof(HINTERNET)); TRACE( "destroying object %p\n", info); + if ( info->htype != WH_HINIT ) + list_remove( &info->entry ); info->destroy( info ); } return TRUE; @@ -191,7 +195,7 @@ BOOL WININET_FreeHandle( HINTERNET hinternet ) { BOOL ret = FALSE; UINT handle = (UINT) hinternet; - LPWININETHANDLEHEADER info = NULL; + LPWININETHANDLEHEADER info = NULL, child, next; EnterCriticalSection( &WININET_cs ); @@ -212,7 +216,16 @@ BOOL WININET_FreeHandle( HINTERNET hinternet ) LeaveCriticalSection( &WININET_cs ); if( info ) + { + /* Free all children as native does */ + LIST_FOR_EACH_ENTRY_SAFE( child, next, &info->children, WININETHANDLEHEADER, entry ) + { + TRACE( "freeing child handle %d for parent handle %d\n", + (UINT)child->hInternet, handle+1); + WININET_FreeHandle( child->hInternet ); + } WININET_Release( info ); + } return ret; } diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h index c82097526ae..0f283e13414 100644 --- a/dlls/wininet/internet.h +++ b/dlls/wininet/internet.h @@ -28,6 +28,7 @@ #endif #include "wine/unicode.h" +#include "wine/list.h" #include #ifdef HAVE_NETDB_H @@ -149,6 +150,8 @@ struct _WININETHANDLEHEADER WININET_object_function close_connection; WININET_object_function destroy; INTERNET_STATUS_CALLBACK lpfnStatusCB; + struct list entry; + struct list children; }; diff --git a/dlls/wininet/urlcache.c b/dlls/wininet/urlcache.c index 2692dfe8c92..d9db16f5fec 100644 --- a/dlls/wininet/urlcache.c +++ b/dlls/wininet/urlcache.c @@ -46,7 +46,6 @@ #include "shlobj.h" #include "wine/unicode.h" -#include "wine/list.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(wininet);