Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/async.c | 26 +++---- dlls/ws2_32/protocol.c | 128 +++++++++++++++++------------------ dlls/ws2_32/socket.c | 70 +++++++++---------- dlls/ws2_32/ws2_32_private.h | 2 +- 4 files changed, 109 insertions(+), 117 deletions(-)
diff --git a/dlls/ws2_32/async.c b/dlls/ws2_32/async.c index 5eecddda062..ffa61149094 100644 --- a/dlls/ws2_32/async.c +++ b/dlls/ws2_32/async.c @@ -34,15 +34,7 @@ * whole stuff did not work anyway to other changes). */
-#include <stdarg.h> -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winuser.h" -#include "winsock2.h" -#include "ws2spi.h" - -#include "wine/debug.h" +#include "ws2_32_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(winsock);
@@ -253,7 +245,7 @@ static void WINAPI async_worker( TP_CALLBACK_INSTANCE *instance, void *context ) struct async_query_header *query = context; LPARAM lparam = query->func( query ); PostMessageW( query->hWnd, query->uMsg, (WPARAM)query->handle, lparam ); - HeapFree( GetProcessHeap(), 0, query ); + free( query ); }
@@ -283,7 +275,7 @@ static HANDLE run_query( HWND hWnd, UINT uMsg, LPARAM (*func)(struct async_query if (!TrySubmitThreadpoolCallback( async_worker, query, NULL )) { SetLastError( WSAEWOULDBLOCK ); - HeapFree( GetProcessHeap(), 0, query ); + free( query ); return 0; } return UlongToHandle( handle ); @@ -300,7 +292,7 @@ HANDLE WINAPI WSAAsyncGetHostByAddr(HWND hWnd, UINT uMsg, LPCSTR addr,
TRACE("hwnd %p, msg %04x, addr %p[%i]\n", hWnd, uMsg, addr, len );
- if (!(aq = HeapAlloc( GetProcessHeap(), 0, sizeof(*aq) + len ))) + if (!(aq = malloc( sizeof(*aq) + len ))) { SetLastError( WSAEWOULDBLOCK ); return 0; @@ -323,7 +315,7 @@ HANDLE WINAPI WSAAsyncGetHostByName(HWND hWnd, UINT uMsg, LPCSTR name,
TRACE("hwnd %p, msg %04x, host %s, buffer %i\n", hWnd, uMsg, debugstr_a(name), buflen );
- if (!(aq = HeapAlloc( GetProcessHeap(), 0, sizeof(*aq) + len ))) + if (!(aq = malloc( sizeof(*aq) + len ))) { SetLastError( WSAEWOULDBLOCK ); return 0; @@ -344,7 +336,7 @@ HANDLE WINAPI WSAAsyncGetProtoByName(HWND hWnd, UINT uMsg, LPCSTR name,
TRACE("hwnd %p, msg %04x, proto %s, buffer %i\n", hWnd, uMsg, debugstr_a(name), buflen );
- if (!(aq = HeapAlloc( GetProcessHeap(), 0, sizeof(*aq) + len ))) + if (!(aq = malloc( sizeof(*aq) + len ))) { SetLastError( WSAEWOULDBLOCK ); return 0; @@ -365,7 +357,7 @@ HANDLE WINAPI WSAAsyncGetProtoByNumber(HWND hWnd, UINT uMsg, INT number,
TRACE("hwnd %p, msg %04x, num %i\n", hWnd, uMsg, number );
- if (!(aq = HeapAlloc( GetProcessHeap(), 0, sizeof(*aq) ))) + if (!(aq = malloc( sizeof(*aq) ))) { SetLastError( WSAEWOULDBLOCK ); return 0; @@ -386,7 +378,7 @@ HANDLE WINAPI WSAAsyncGetServByName(HWND hWnd, UINT uMsg, LPCSTR name,
TRACE("hwnd %p, msg %04x, name %s, proto %s\n", hWnd, uMsg, debugstr_a(name), debugstr_a(proto));
- if (!(aq = HeapAlloc( GetProcessHeap(), 0, sizeof(*aq) + len1 + len2 ))) + if (!(aq = malloc( sizeof(*aq) + len1 + len2 ))) { SetLastError( WSAEWOULDBLOCK ); return 0; @@ -417,7 +409,7 @@ HANDLE WINAPI WSAAsyncGetServByPort(HWND hWnd, UINT uMsg, INT port,
TRACE("hwnd %p, msg %04x, port %i, proto %s\n", hWnd, uMsg, port, debugstr_a(proto));
- if (!(aq = HeapAlloc( GetProcessHeap(), 0, sizeof(*aq) + len ))) + if (!(aq = malloc( sizeof(*aq) + len ))) { SetLastError( WSAEWOULDBLOCK ); return 0; diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c index 733ef102eea..0b48515091b 100644 --- a/dlls/ws2_32/protocol.c +++ b/dlls/ws2_32/protocol.c @@ -38,10 +38,10 @@ static char *get_fqdn(void)
GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, NULL, &size ); if (GetLastError() != ERROR_MORE_DATA) return NULL; - if (!(ret = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL; + if (!(ret = malloc( size ))) return NULL; if (!GetComputerNameExA( ComputerNamePhysicalDnsFullyQualified, ret, &size )) { - HeapFree( GetProcessHeap(), 0, ret ); + free( ret ); return NULL; } return ret; @@ -57,14 +57,14 @@ static int do_getaddrinfo( const char *node, const char *service,
for (;;) { - if (!(params.info = HeapAlloc( GetProcessHeap(), 0, size ))) + if (!(params.info = malloc( size ))) return WSA_NOT_ENOUGH_MEMORY; if (!(ret = WS_CALL( getaddrinfo, ¶ms ))) { *info = params.info; return ret; } - HeapFree( GetProcessHeap(), 0, params.info ); + free( params.info ); if (ret != ERROR_INSUFFICIENT_BUFFER) return ret; } } @@ -103,8 +103,8 @@ int WINAPI getaddrinfo( const char *node, const char *service,
if (node[0] == '[' && (close_bracket = strchr(node + 1, ']'))) { - nodev6 = HeapAlloc( GetProcessHeap(), 0, close_bracket - node ); - if (!nodev6) return WSA_NOT_ENOUGH_MEMORY; + if (!(nodev6 = malloc( close_bracket - node ))) + return WSA_NOT_ENOUGH_MEMORY; lstrcpynA( nodev6, node + 1, close_bracket - node ); node = nodev6; } @@ -117,7 +117,7 @@ int WINAPI getaddrinfo( const char *node, const char *service, { if (!fqdn && !(fqdn = get_fqdn())) { - HeapFree( GetProcessHeap(), 0, nodev6 ); + free( nodev6 ); return WSA_NOT_ENOUGH_MEMORY; } if (!strcmp( fqdn, node ) || (!strncmp( fqdn, node, strlen( node ) ) && fqdn[strlen( node )] == '.')) @@ -136,8 +136,8 @@ int WINAPI getaddrinfo( const char *node, const char *service, } }
- HeapFree( GetProcessHeap(), 0, fqdn ); - HeapFree( GetProcessHeap(), 0, nodev6 ); + free( fqdn ); + free( nodev6 );
if (!ret && TRACE_ON(winsock)) { @@ -160,7 +160,7 @@ static ADDRINFOEXW *addrinfo_AtoW( const struct addrinfo *ai ) { ADDRINFOEXW *ret;
- if (!(ret = HeapAlloc( GetProcessHeap(), 0, sizeof(ADDRINFOEXW) ))) return NULL; + if (!(ret = malloc( sizeof(ADDRINFOEXW) ))) return NULL; ret->ai_flags = ai->ai_flags; ret->ai_family = ai->ai_family; ret->ai_socktype = ai->ai_socktype; @@ -175,19 +175,19 @@ static ADDRINFOEXW *addrinfo_AtoW( const struct addrinfo *ai ) if (ai->ai_canonname) { int len = MultiByteToWideChar( CP_ACP, 0, ai->ai_canonname, -1, NULL, 0 ); - if (!(ret->ai_canonname = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) + if (!(ret->ai_canonname = malloc( len * sizeof(WCHAR) ))) { - HeapFree( GetProcessHeap(), 0, ret ); + free( ret ); return NULL; } MultiByteToWideChar( CP_ACP, 0, ai->ai_canonname, -1, ret->ai_canonname, len ); } if (ai->ai_addr) { - if (!(ret->ai_addr = HeapAlloc( GetProcessHeap(), 0, ai->ai_addrlen ))) + if (!(ret->ai_addr = malloc( ai->ai_addrlen ))) { - HeapFree( GetProcessHeap(), 0, ret->ai_canonname ); - HeapFree( GetProcessHeap(), 0, ret ); + free( ret->ai_canonname ); + free( ret ); return NULL; } memcpy( ret->ai_addr, ai->ai_addr, ai->ai_addrlen ); @@ -217,7 +217,7 @@ static struct addrinfo *addrinfo_WtoA( const struct addrinfoW *ai ) { struct addrinfo *ret;
- if (!(ret = HeapAlloc( GetProcessHeap(), 0, sizeof(struct addrinfo) ))) return NULL; + if (!(ret = malloc( sizeof(struct addrinfo) ))) return NULL; ret->ai_flags = ai->ai_flags; ret->ai_family = ai->ai_family; ret->ai_socktype = ai->ai_socktype; @@ -229,19 +229,19 @@ static struct addrinfo *addrinfo_WtoA( const struct addrinfoW *ai ) if (ai->ai_canonname) { int len = WideCharToMultiByte( CP_ACP, 0, ai->ai_canonname, -1, NULL, 0, NULL, NULL ); - if (!(ret->ai_canonname = HeapAlloc( GetProcessHeap(), 0, len ))) + if (!(ret->ai_canonname = malloc( len ))) { - HeapFree( GetProcessHeap(), 0, ret ); + free( ret ); return NULL; } WideCharToMultiByte( CP_ACP, 0, ai->ai_canonname, -1, ret->ai_canonname, len, NULL, NULL ); } if (ai->ai_addr) { - if (!(ret->ai_addr = HeapAlloc( GetProcessHeap(), 0, sizeof(struct sockaddr) ))) + if (!(ret->ai_addr = malloc( sizeof(struct sockaddr) ))) { - HeapFree( GetProcessHeap(), 0, ret->ai_canonname ); - HeapFree( GetProcessHeap(), 0, ret ); + free( ret->ai_canonname ); + free( ret ); return NULL; } memcpy( ret->ai_addr, ai->ai_addr, sizeof(struct sockaddr) ); @@ -276,9 +276,9 @@ static void WINAPI getaddrinfo_callback(TP_CALLBACK_INSTANCE *instance, void *co freeaddrinfo(res); }
- HeapFree( GetProcessHeap(), 0, args->nodename ); - HeapFree( GetProcessHeap(), 0, args->servname ); - HeapFree( GetProcessHeap(), 0, args ); + free( args->nodename ); + free( args->servname ); + free( args );
overlapped->Internal = ret; if (completion_routine) completion_routine( ret, 0, overlapped ); @@ -322,20 +322,20 @@ static int getaddrinfoW( const WCHAR *nodename, const WCHAR *servname, ret = EAI_FAIL; goto end; } - if (!(local_nodenameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) goto end; + if (!(local_nodenameW = malloc( len * sizeof(WCHAR) ))) goto end; IdnToAscii( 0, nodename, -1, local_nodenameW, len ); } } if (local_nodenameW) { len = WideCharToMultiByte( CP_ACP, 0, local_nodenameW, -1, NULL, 0, NULL, NULL ); - if (!(nodenameA = HeapAlloc( GetProcessHeap(), 0, len ))) goto end; + if (!(nodenameA = malloc( len ))) goto end; WideCharToMultiByte( CP_ACP, 0, local_nodenameW, -1, nodenameA, len, NULL, NULL ); } if (servname) { len = WideCharToMultiByte( CP_ACP, 0, servname, -1, NULL, 0, NULL, NULL ); - if (!(servnameA = HeapAlloc( GetProcessHeap(), 0, len ))) goto end; + if (!(servnameA = malloc( len ))) goto end; WideCharToMultiByte( CP_ACP, 0, servname, -1, servnameA, len, NULL, NULL ); }
@@ -349,7 +349,7 @@ static int getaddrinfoW( const WCHAR *nodename, const WCHAR *servname, goto end; }
- if (!(args = HeapAlloc( GetProcessHeap(), 0, sizeof(*args) + sizeof(*args->hints) ))) goto end; + if (!(args = malloc( sizeof(*args) + sizeof(*args->hints) ))) goto end; args->overlapped = overlapped; args->completion_routine = completion_routine; args->result = res; @@ -368,13 +368,13 @@ static int getaddrinfoW( const WCHAR *nodename, const WCHAR *servname, overlapped->Internal = WSAEINPROGRESS; if (!TrySubmitThreadpoolCallback( getaddrinfo_callback, args, NULL )) { - HeapFree( GetProcessHeap(), 0, args ); + free( args ); ret = GetLastError(); goto end; }
if (local_nodenameW != nodename) - HeapFree( GetProcessHeap(), 0, local_nodenameW ); + free( local_nodenameW ); SetLastError( ERROR_IO_PENDING ); return ERROR_IO_PENDING; } @@ -388,9 +388,9 @@ static int getaddrinfoW( const WCHAR *nodename, const WCHAR *servname,
end: if (local_nodenameW != nodename) - HeapFree( GetProcessHeap(), 0, local_nodenameW ); - HeapFree( GetProcessHeap(), 0, nodenameA ); - HeapFree( GetProcessHeap(), 0, servnameA ); + free( local_nodenameW ); + free( nodenameA ); + free( servnameA ); return ret; }
@@ -484,7 +484,7 @@ void WINAPI freeaddrinfo( struct addrinfo *info ) { TRACE( "%p\n", info );
- HeapFree( GetProcessHeap(), 0, info ); + free( info ); }
@@ -496,10 +496,10 @@ void WINAPI FreeAddrInfoW( ADDRINFOW *ai ) while (ai) { ADDRINFOW *next; - HeapFree( GetProcessHeap(), 0, ai->ai_canonname ); - HeapFree( GetProcessHeap(), 0, ai->ai_addr ); + free( ai->ai_canonname ); + free( ai->ai_addr ); next = ai->ai_next; - HeapFree( GetProcessHeap(), 0, ai ); + free( ai ); ai = next; } } @@ -515,10 +515,10 @@ void WINAPI FreeAddrInfoEx( ADDRINFOEXA *ai ) while (ai) { ADDRINFOEXA *next; - HeapFree( GetProcessHeap(), 0, ai->ai_canonname ); - HeapFree( GetProcessHeap(), 0, ai->ai_addr ); + free( ai->ai_canonname ); + free( ai->ai_addr ); next = ai->ai_next; - HeapFree( GetProcessHeap(), 0, ai ); + free( ai ); ai = next; } } @@ -534,10 +534,10 @@ void WINAPI FreeAddrInfoExW( ADDRINFOEXW *ai ) while (ai) { ADDRINFOEXW *next; - HeapFree( GetProcessHeap(), 0, ai->ai_canonname ); - HeapFree( GetProcessHeap(), 0, ai->ai_addr ); + free( ai->ai_canonname ); + free( ai->ai_addr ); next = ai->ai_next; - HeapFree( GetProcessHeap(), 0, ai ); + free( ai ); ai = next; } } @@ -567,11 +567,11 @@ int WINAPI GetNameInfoW( const SOCKADDR *addr, socklen_t addr_len, WCHAR *host, int ret; char *hostA = NULL, *servA = NULL;
- if (host && (!(hostA = HeapAlloc( GetProcessHeap(), 0, host_len )))) + if (host && !(hostA = malloc( host_len ))) return EAI_MEMORY; - if (serv && (!(servA = HeapAlloc( GetProcessHeap(), 0, serv_len )))) + if (serv && !(servA = malloc( serv_len ))) { - HeapFree( GetProcessHeap(), 0, hostA ); + free( hostA ); return EAI_MEMORY; }
@@ -582,8 +582,8 @@ int WINAPI GetNameInfoW( const SOCKADDR *addr, socklen_t addr_len, WCHAR *host, if (serv) MultiByteToWideChar( CP_ACP, 0, servA, -1, serv, serv_len ); }
- HeapFree( GetProcessHeap(), 0, hostA ); - HeapFree( GetProcessHeap(), 0, servA ); + free( hostA ); + free( servA ); return ret; }
@@ -594,9 +594,9 @@ static struct hostent *get_hostent_buffer( unsigned int size ) if (data->he_buffer) { if (data->he_len >= size) return data->he_buffer; - HeapFree( GetProcessHeap(), 0, data->he_buffer ); + free( data->he_buffer ); } - data->he_buffer = HeapAlloc( GetProcessHeap(), 0, (data->he_len = size) ); + data->he_buffer = malloc( (data->he_len = size) ); if (!data->he_buffer) SetLastError(WSAENOBUFS); return data->he_buffer; } @@ -722,8 +722,8 @@ static struct hostent *get_local_ips( char *hostname ) if (GetIpForwardTable( NULL, &route_size, FALSE ) != ERROR_INSUFFICIENT_BUFFER) return NULL;
- adapters = HeapAlloc( GetProcessHeap(), 0, adap_size ); - routes = HeapAlloc( GetProcessHeap(), 0, route_size ); + adapters = malloc( adap_size ); + routes = malloc( route_size ); if (!adapters || !routes) goto cleanup;
@@ -759,7 +759,7 @@ static struct hostent *get_local_ips( char *hostname ) } if (exists) continue; - route_addrs = heap_realloc( route_addrs, (numroutes + 1) * sizeof(struct route) ); + route_addrs = realloc( route_addrs, (numroutes + 1) * sizeof(struct route) ); if (!route_addrs) goto cleanup; route_addrs[numroutes].interface = ifindex; @@ -808,9 +808,9 @@ static struct hostent *get_local_ips( char *hostname ) *(struct in_addr *)hostlist->h_addr_list[i] = route_addrs[i].addr;
cleanup: - HeapFree( GetProcessHeap(), 0, route_addrs ); - HeapFree( GetProcessHeap(), 0, adapters ); - HeapFree( GetProcessHeap(), 0, routes ); + free( route_addrs ); + free( adapters ); + free( routes ); return hostlist; }
@@ -1009,10 +1009,10 @@ static struct protoent *get_protoent_buffer( unsigned int size ) if (data->pe_buffer) { if (data->pe_len >= size) return data->pe_buffer; - HeapFree( GetProcessHeap(), 0, data->pe_buffer ); + free( data->pe_buffer ); } data->pe_len = size; - data->pe_buffer = HeapAlloc( GetProcessHeap(), 0, size ); + data->pe_buffer = malloc( size ); if (!data->pe_buffer) SetLastError( WSAENOBUFS ); return data->pe_buffer; } @@ -1191,10 +1191,10 @@ static struct servent *get_servent_buffer( int size ) if (data->se_buffer) { if (data->se_len >= size) return data->se_buffer; - HeapFree( GetProcessHeap(), 0, data->se_buffer ); + free( data->se_buffer ); } data->se_len = size; - data->se_buffer = HeapAlloc( GetProcessHeap(), 0, size ); + data->se_buffer = malloc( size ); if (!data->se_buffer) SetLastError( WSAENOBUFS ); return data->se_buffer; } @@ -1481,7 +1481,7 @@ int WINAPI InetPtonW( int family, const WCHAR *addr, void *buffer ) }
len = WideCharToMultiByte( CP_ACP, 0, addr, -1, NULL, 0, NULL, NULL ); - if (!(addrA = HeapAlloc( GetProcessHeap(), 0, len ))) + if (!(addrA = malloc( len ))) { SetLastError( WSA_NOT_ENOUGH_MEMORY ); return -1; @@ -1491,7 +1491,7 @@ int WINAPI InetPtonW( int family, const WCHAR *addr, void *buffer ) ret = inet_pton( family, addrA, buffer ); if (!ret) SetLastError( WSAEINVAL );
- HeapFree( GetProcessHeap(), 0, addrA ); + free( addrA ); return ret; }
@@ -1627,14 +1627,14 @@ int WINAPI WSAStringToAddressW( WCHAR *string, int family, WSAPROTOCOL_INFOW *pr }
sizeA = WideCharToMultiByte( CP_ACP, 0, string, -1, NULL, 0, NULL, NULL ); - if (!(stringA = HeapAlloc( GetProcessHeap(), 0, sizeA ))) + if (!(stringA = malloc( sizeA ))) { SetLastError( WSA_NOT_ENOUGH_MEMORY ); return -1; } WideCharToMultiByte( CP_ACP, 0, string, -1, stringA, sizeA, NULL, NULL ); ret = WSAStringToAddressA( stringA, family, protocol_infoA, addr, addr_len ); - HeapFree( GetProcessHeap(), 0, stringA ); + free( stringA ); return ret; }
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index c991d212a07..a5461ae9327 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -361,7 +361,7 @@ static BOOL socket_list_add(SOCKET socket) } } new_size = max(socket_list_size * 2, 8); - if (!(new_array = heap_realloc(socket_list, new_size * sizeof(*socket_list)))) + if (!(new_array = realloc( socket_list, new_size * sizeof(*socket_list) ))) { LeaveCriticalSection(&cs_socket_list); return FALSE; @@ -508,30 +508,30 @@ static DWORD NtStatusToWSAError( NTSTATUS status )
struct per_thread_data *get_per_thread_data(void) { - struct per_thread_data * ptb = NtCurrentTeb()->WinSockData; - /* lazy initialization */ - if (!ptb) + struct per_thread_data *data = NtCurrentTeb()->WinSockData; + + if (!data) { - ptb = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ptb) ); - NtCurrentTeb()->WinSockData = ptb; + data = calloc( 1, sizeof(*data) ); + NtCurrentTeb()->WinSockData = data; } - return ptb; + return data; }
static void free_per_thread_data(void) { - struct per_thread_data * ptb = NtCurrentTeb()->WinSockData; + struct per_thread_data *data = NtCurrentTeb()->WinSockData;
- if (!ptb) return; + if (!data) return;
- CloseHandle( ptb->sync_event ); + CloseHandle( data->sync_event );
/* delete scratch buffers */ - HeapFree( GetProcessHeap(), 0, ptb->he_buffer ); - HeapFree( GetProcessHeap(), 0, ptb->se_buffer ); - HeapFree( GetProcessHeap(), 0, ptb->pe_buffer ); + free( data->he_buffer ); + free( data->se_buffer ); + free( data->pe_buffer );
- HeapFree( GetProcessHeap(), 0, ptb ); + free( data ); NtCurrentTeb()->WinSockData = NULL; }
@@ -1108,12 +1108,12 @@ int WINAPI bind( SOCKET s, const struct sockaddr *addr, int len )
if (!(sync_event = get_sync_event())) return -1;
- params = HeapAlloc( GetProcessHeap(), 0, sizeof(int) + len ); - ret_addr = HeapAlloc( GetProcessHeap(), 0, len ); + params = malloc( sizeof(int) + len ); + ret_addr = malloc( len ); if (!params || !ret_addr) { - HeapFree( GetProcessHeap(), 0, params ); - HeapFree( GetProcessHeap(), 0, ret_addr ); + free( params ); + free( ret_addr ); SetLastError( WSAENOBUFS ); return -1; } @@ -1129,8 +1129,8 @@ int WINAPI bind( SOCKET s, const struct sockaddr *addr, int len ) status = io.u.Status; }
- HeapFree( GetProcessHeap(), 0, params ); - HeapFree( GetProcessHeap(), 0, ret_addr ); + free( params ); + free( ret_addr );
SetLastError( NtStatusToWSAError( status ) ); return status ? -1 : 0; @@ -1175,7 +1175,7 @@ int WINAPI connect( SOCKET s, const struct sockaddr *addr, int len )
if (!(sync_event = get_sync_event())) return -1;
- if (!(params = HeapAlloc( GetProcessHeap(), 0, sizeof(*params) + len ))) + if (!(params = malloc( sizeof(*params) + len ))) { SetLastError( ERROR_NOT_ENOUGH_MEMORY ); return -1; @@ -1186,7 +1186,7 @@ int WINAPI connect( SOCKET s, const struct sockaddr *addr, int len )
status = NtDeviceIoControlFile( (HANDLE)s, sync_event, NULL, NULL, &io, IOCTL_AFD_WINE_CONNECT, params, sizeof(*params) + len, NULL, 0 ); - HeapFree( GetProcessHeap(), 0, params ); + free( params ); if (status == STATUS_PENDING) { if (WaitForSingleObject( sync_event, INFINITE ) == WAIT_FAILED) return -1; @@ -1235,7 +1235,7 @@ static BOOL WINAPI WS2_ConnectEx( SOCKET s, const struct sockaddr *name, int nam overlapped->Internal = STATUS_PENDING; overlapped->InternalHigh = 0;
- if (!(params = HeapAlloc( GetProcessHeap(), 0, sizeof(*params) + namelen + send_len ))) + if (!(params = malloc( sizeof(*params) + namelen + send_len ))) { SetLastError( ERROR_NOT_ENOUGH_MEMORY ); return SOCKET_ERROR; @@ -1248,7 +1248,7 @@ static BOOL WINAPI WS2_ConnectEx( SOCKET s, const struct sockaddr *name, int nam status = NtDeviceIoControlFile( SOCKET2HANDLE(s), overlapped->hEvent, NULL, cvalue, (IO_STATUS_BLOCK *)overlapped, IOCTL_AFD_WINE_CONNECT, params, sizeof(*params) + namelen + send_len, NULL, 0 ); - HeapFree( GetProcessHeap(), 0, params ); + free( params ); if (ret_len) *ret_len = overlapped->InternalHigh; SetLastError( NtStatusToWSAError( status ) ); return !status; @@ -2018,7 +2018,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if (GetAdaptersInfo(NULL, &size) == ERROR_BUFFER_OVERFLOW) { - IP_ADAPTER_INFO *p, *table = HeapAlloc(GetProcessHeap(), 0, size); + IP_ADAPTER_INFO *p, *table = malloc( size ); NTSTATUS status = STATUS_SUCCESS; SOCKET_ADDRESS_LIST *sa_list; SOCKADDR_IN *sockaddr; @@ -2029,7 +2029,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if (!table || GetAdaptersInfo(table, &size)) { - HeapFree(GetProcessHeap(), 0, table); + free( table ); SetLastError( WSAEINVAL ); return -1; } @@ -2041,7 +2041,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID if (total > out_size || !out_buff) { *ret_size = total; - HeapFree(GetProcessHeap(), 0, table); + free( table ); SetLastError( WSAEFAULT ); return -1; } @@ -2064,7 +2064,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID i++; }
- HeapFree(GetProcessHeap(), 0, table); + free( table );
ret = server_ioctl_sock( s, IOCTL_AFD_WINE_COMPLETE_ASYNC, &status, sizeof(status), NULL, 0, ret_size, overlapped, completion ); @@ -2163,10 +2163,10 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID SetLastError( WSAEFAULT ); return -1; } - ipAddrTable = HeapAlloc( GetProcessHeap(), 0, size ); + ipAddrTable = malloc( size ); if (GetIpAddrTable( ipAddrTable, &size, FALSE )) { - HeapFree( GetProcessHeap(), 0, ipAddrTable ); + free( ipAddrTable ); SetLastError( WSAEFAULT ); return -1; } @@ -2180,14 +2180,14 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID { ERR("no matching IP address for interface %d\n", row.dwForwardIfIndex); - HeapFree( GetProcessHeap(), 0, ipAddrTable ); + free( ipAddrTable ); SetLastError( WSAEFAULT ); return -1; } saddr_in->sin_family = AF_INET; saddr_in->sin_addr.S_un.S_addr = ipAddrTable->table[found_index].dwAddr; saddr_in->sin_port = 0; - HeapFree( GetProcessHeap(), 0, ipAddrTable ); + free( ipAddrTable );
ret = server_ioctl_sock( s, IOCTL_AFD_WINE_COMPLETE_ASYNC, &status, sizeof(status), NULL, 0, ret_size, overlapped, completion ); @@ -2520,7 +2520,7 @@ int WINAPI WSAPoll( WSAPOLLFD *fds, ULONG count, int timeout ) if (!(sync_event = get_sync_event())) return -1;
params_size = offsetof( struct afd_poll_params, sockets[count] ); - if (!(params = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, params_size ))) + if (!(params = calloc( params_size, 1 ))) { SetLastError(WSAENOBUFS); return SOCKET_ERROR; @@ -2566,7 +2566,7 @@ int WINAPI WSAPoll( WSAPOLLFD *fds, ULONG count, int timeout ) { if (WaitForSingleObject( sync_event, INFINITE ) == WAIT_FAILED) { - HeapFree( GetProcessHeap(), 0, params ); + free( params ); return -1; } status = io.u.Status; @@ -2604,7 +2604,7 @@ int WINAPI WSAPoll( WSAPOLLFD *fds, ULONG count, int timeout ) } if (status == STATUS_TIMEOUT) status = STATUS_SUCCESS;
- HeapFree( GetProcessHeap(), 0, params ); + free( params );
SetLastError( NtStatusToWSAError( status ) ); return status ? -1 : ret_count; diff --git a/dlls/ws2_32/ws2_32_private.h b/dlls/ws2_32/ws2_32_private.h index 5e2075b5c9c..85f6b4dbc1c 100644 --- a/dlls/ws2_32/ws2_32_private.h +++ b/dlls/ws2_32/ws2_32_private.h @@ -21,6 +21,7 @@
#include <stdarg.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <limits.h>
@@ -50,7 +51,6 @@ #include "wine/afd.h" #include "wine/debug.h" #include "wine/exception.h" -#include "wine/heap.h" #include "wine/unixlib.h"
#define DECLARE_CRITICAL_SECTION(cs) \
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/ws2_32/protocol.c | 46 ++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 17 deletions(-)
diff --git a/dlls/ws2_32/protocol.c b/dlls/ws2_32/protocol.c index 0b48515091b..e768476c9ba 100644 --- a/dlls/ws2_32/protocol.c +++ b/dlls/ws2_32/protocol.c @@ -591,13 +591,18 @@ int WINAPI GetNameInfoW( const SOCKADDR *addr, socklen_t addr_len, WCHAR *host, static struct hostent *get_hostent_buffer( unsigned int size ) { struct per_thread_data *data = get_per_thread_data(); - if (data->he_buffer) + struct hostent *new_buffer; + + if (data->he_len < size) { - if (data->he_len >= size) return data->he_buffer; - free( data->he_buffer ); + if (!(new_buffer = realloc( data->he_buffer, size ))) + { + SetLastError( WSAENOBUFS ); + return NULL; + } + data->he_buffer = new_buffer; + data->he_len = size; } - data->he_buffer = malloc( (data->he_len = size) ); - if (!data->he_buffer) SetLastError(WSAENOBUFS); return data->he_buffer; }
@@ -1005,15 +1010,18 @@ static char *next_non_space( const char *p, const char *end ) static struct protoent *get_protoent_buffer( unsigned int size ) { struct per_thread_data *data = get_per_thread_data(); + struct protoent *new_buffer;
- if (data->pe_buffer) + if (data->pe_len < size) { - if (data->pe_len >= size) return data->pe_buffer; - free( data->pe_buffer ); + if (!(new_buffer = realloc( data->pe_buffer, size ))) + { + SetLastError( WSAENOBUFS ); + return NULL; + } + data->pe_buffer = new_buffer; + data->pe_len = size; } - data->pe_len = size; - data->pe_buffer = malloc( size ); - if (!data->pe_buffer) SetLastError( WSAENOBUFS ); return data->pe_buffer; }
@@ -1188,14 +1196,18 @@ struct protoent * WINAPI getprotobynumber( int number ) static struct servent *get_servent_buffer( int size ) { struct per_thread_data *data = get_per_thread_data(); - if (data->se_buffer) + struct servent *new_buffer; + + if (data->se_len < size) { - if (data->se_len >= size) return data->se_buffer; - free( data->se_buffer ); + if (!(new_buffer = realloc( data->se_buffer, size ))) + { + SetLastError( WSAENOBUFS ); + return NULL; + } + data->se_buffer = new_buffer; + data->se_len = size; } - data->se_len = size; - data->se_buffer = malloc( size ); - if (!data->se_buffer) SetLastError( WSAENOBUFS ); return data->se_buffer; }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=95882
Your paranoid android.
=== debiant2 (32 bit report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (32 bit Chinese:China report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (32 bit WoW report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (64 bit WoW report) ===
ws2_32: sock.c:6393: Test failed: got error 87
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- I don't know what application wants this, if any do, but it at least seems better than reporting a fake value.
dlls/ws2_32/socket.c | 29 ++++++++--------------------- include/wine/afd.h | 1 + server/sock.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index a5461ae9327..1c23da8c571 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1424,6 +1424,14 @@ int WINAPI getsockopt( SOCKET s, int level, int optname, char *optval, int *optl return 0; }
+ case SO_CONNECT_TIME: + if (!optlen || !optval) + { + SetLastError( WSAEFAULT ); + return -1; + } + return server_getsockopt( s, IOCTL_AFD_WINE_GET_SO_CONNECT_TIME, optval, optlen ); + case SO_DEBUG: WARN( "returning 0 for SO_DEBUG\n" ); *(DWORD *)optval = 0; @@ -1450,27 +1458,6 @@ int WINAPI getsockopt( SOCKET s, int level, int optname, char *optval, int *optl return ret; }
- case SO_CONNECT_TIME: - { - static int pretendtime = 0; - struct sockaddr addr; - int len = sizeof(addr); - - if (!optlen || *optlen < sizeof(DWORD) || !optval) - { - SetLastError(WSAEFAULT); - return SOCKET_ERROR; - } - if (getpeername(s, &addr, &len) == SOCKET_ERROR) - *(DWORD *)optval = ~0u; - else - { - if (!pretendtime) FIXME("SO_CONNECT_TIME - faking results\n"); - *(DWORD *)optval = pretendtime++; - } - *optlen = sizeof(DWORD); - return ret; - } /* As mentioned in setsockopt, Windows ignores this, so we * always return true here */ case SO_DONTROUTE: diff --git a/include/wine/afd.h b/include/wine/afd.h index 43e140c91c6..1eb174eb5f5 100644 --- a/include/wine/afd.h +++ b/include/wine/afd.h @@ -232,6 +232,7 @@ struct afd_get_events_params #define IOCTL_AFD_WINE_SET_IPV6_RECVPKTINFO WINE_AFD_IOC(289) #define IOCTL_AFD_WINE_GET_IPV6_RECVTCLASS WINE_AFD_IOC(290) #define IOCTL_AFD_WINE_SET_IPV6_RECVTCLASS WINE_AFD_IOC(291) +#define IOCTL_AFD_WINE_GET_SO_CONNECT_TIME WINE_AFD_IOC(292)
struct afd_create_params { diff --git a/server/sock.c b/server/sock.c index 27477200ed0..50bfc08e145 100644 --- a/server/sock.c +++ b/server/sock.c @@ -2807,6 +2807,23 @@ static int sock_ioctl( struct fd *fd, ioctl_code_t code, struct async *async ) return 0; }
+ case IOCTL_AFD_WINE_GET_SO_CONNECT_TIME: + { + DWORD time = ~0u; + + if (get_reply_max_size() < sizeof(time)) + { + set_error( STATUS_BUFFER_TOO_SMALL ); + return 0; + } + + if (sock->state == SOCK_CONNECTED) + time = (current_time - sock->connect_time) / 10000000; + + set_reply_data( &time, sizeof(time) ); + return 1; + } + default: set_error( STATUS_NOT_SUPPORTED ); return 0;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=95883
Your paranoid android.
=== debiant2 (32 bit report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (32 bit Chinese:China report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (32 bit WoW report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (64 bit WoW report) ===
ws2_32: sock.c:6393: Test failed: got error 87
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=95881
Your paranoid android.
=== debiant2 (32 bit report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (32 bit Chinese:China report) ===
ws2_32: sock.c:1135: Test failed: wait failed, error 258 sock.c:6393: Test failed: got error 87
=== debiant2 (32 bit WoW report) ===
ws2_32: sock.c:6393: Test failed: got error 87
=== debiant2 (64 bit WoW report) ===
ws2_32: sock.c:6393: Test failed: got error 87