Commit 4f961d9e authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Use CRT memory allocators.

parent ed9c1fb1
......@@ -49,7 +49,7 @@ static struct domain *add_domain( struct session *session, WCHAR *name )
{
struct domain *domain;
if (!(domain = heap_alloc_zero( sizeof(struct domain) ))) return NULL;
if (!(domain = calloc( 1, sizeof(*domain) ))) return NULL;
list_init( &domain->entry );
list_init( &domain->cookies );
......@@ -89,10 +89,10 @@ static BOOL domain_match( const WCHAR *name, struct domain *domain, BOOL partial
static void free_cookie( struct cookie *cookie )
{
heap_free( cookie->name );
heap_free( cookie->value );
heap_free( cookie->path );
heap_free( cookie );
free( cookie->name );
free( cookie->value );
free( cookie->path );
free( cookie );
}
static void delete_cookie( struct cookie *cookie )
......@@ -113,8 +113,8 @@ static void delete_domain( struct domain *domain )
}
list_remove( &domain->entry );
heap_free( domain->name );
heap_free( domain );
free( domain->name );
free( domain );
}
void destroy_cookies( struct session *session )
......@@ -170,12 +170,12 @@ static struct cookie *parse_cookie( const WCHAR *string )
while (len && string[len - 1] == ' ') len--;
if (!len) return NULL;
if (!(cookie = heap_alloc_zero( sizeof(struct cookie) ))) return NULL;
if (!(cookie = calloc( 1, sizeof(*cookie) ))) return NULL;
list_init( &cookie->entry );
if (!(cookie->name = heap_alloc( (len + 1) * sizeof(WCHAR) )))
if (!(cookie->name = malloc( (len + 1) * sizeof(WCHAR) )))
{
heap_free( cookie );
free( cookie );
return NULL;
}
memcpy( cookie->name, string, len * sizeof(WCHAR) );
......@@ -187,7 +187,7 @@ static struct cookie *parse_cookie( const WCHAR *string )
len = lstrlenW( p );
while (len && p[len - 1] == ' ') len--;
if (!(cookie->value = heap_alloc( (len + 1) * sizeof(WCHAR) )))
if (!(cookie->value = malloc( (len + 1) * sizeof(WCHAR) )))
{
free_cookie( cookie );
return NULL;
......@@ -207,9 +207,9 @@ struct attr
static void free_attr( struct attr *attr )
{
if (!attr) return;
heap_free( attr->name );
heap_free( attr->value );
heap_free( attr );
free( attr->name );
free( attr->value );
free( attr );
}
static struct attr *parse_attr( const WCHAR *str, int *used )
......@@ -224,10 +224,10 @@ static struct attr *parse_attr( const WCHAR *str, int *used )
len = q - p;
if (!len) return NULL;
if (!(attr = heap_alloc( sizeof(struct attr) ))) return NULL;
if (!(attr->name = heap_alloc( (len + 1) * sizeof(WCHAR) )))
if (!(attr = malloc( sizeof(*attr) ))) return NULL;
if (!(attr->name = malloc( (len + 1) * sizeof(WCHAR) )))
{
heap_free( attr );
free( attr );
return NULL;
}
memcpy( attr->name, p, len * sizeof(WCHAR) );
......@@ -244,7 +244,7 @@ static struct attr *parse_attr( const WCHAR *str, int *used )
len = q - p;
while (len && p[len - 1] == ' ') len--;
if (!(attr->value = heap_alloc( (len + 1) * sizeof(WCHAR) )))
if (!(attr->value = malloc( (len + 1) * sizeof(WCHAR) )))
{
free_attr( attr );
return NULL;
......@@ -271,7 +271,7 @@ BOOL set_cookies( struct request *request, const WCHAR *cookies )
int len, used;
len = lstrlenW( cookies );
if (!(buffer = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return FALSE;
if (!(buffer = malloc( (len + 1) * sizeof(WCHAR) ))) return FALSE;
lstrcpyW( buffer, cookies );
p = buffer;
......@@ -279,7 +279,7 @@ BOOL set_cookies( struct request *request, const WCHAR *cookies )
if (*p == ';') *p++ = 0;
if (!(cookie = parse_cookie( buffer )))
{
heap_free( buffer );
free( buffer );
return FALSE;
}
len = lstrlenW( p );
......@@ -312,10 +312,10 @@ BOOL set_cookies( struct request *request, const WCHAR *cookies )
end:
if (!ret) free_cookie( cookie );
if (domain) free_attr( domain );
else heap_free( cookie_domain );
else free( cookie_domain );
if (path) free_attr( path );
else heap_free( cookie_path );
heap_free( buffer );
else free( cookie_path );
free( buffer );
return ret;
}
......@@ -349,7 +349,7 @@ DWORD add_cookie_headers( struct request *request )
len = len_cookie + len_name;
if (cookie->value) len += lstrlenW( cookie->value ) + 1;
if (!(header = heap_alloc( (len + 1) * sizeof(WCHAR) )))
if (!(header = malloc( (len + 1) * sizeof(WCHAR) )))
{
LeaveCriticalSection( &session->cs );
return ERROR_OUTOFMEMORY;
......@@ -366,7 +366,7 @@ DWORD add_cookie_headers( struct request *request )
TRACE("%s\n", debugstr_w(header));
ret = add_request_headers( request, header, len,
WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON );
heap_free( header );
free( header );
}
}
}
......
......@@ -94,14 +94,17 @@ HINTERNET alloc_handle( struct object_header *hdr )
if (!max_handles)
{
num = HANDLE_CHUNK_SIZE;
if (!(p = heap_alloc_zero( sizeof(ULONG_PTR) * num ))) goto end;
if (!(p = calloc( 1, sizeof(ULONG_PTR) * num ))) goto end;
handles = p;
max_handles = num;
}
if (max_handles == next_handle)
{
size_t new_size, old_size = max_handles * sizeof(ULONG_PTR);
num = max_handles * 2;
if (!(p = heap_realloc_zero( handles, sizeof(ULONG_PTR) * num ))) goto end;
new_size = num * sizeof(ULONG_PTR);
if (!(p = realloc( handles, new_size ))) goto end;
memset( (char *)p + old_size, 0, new_size - old_size );
handles = p;
max_handles = num;
}
......
......@@ -187,14 +187,14 @@ DWORD netconn_create( struct hostdata *host, const struct sockaddr_storage *sock
winsock_init();
if (!(conn = heap_alloc_zero( sizeof(*conn) ))) return ERROR_OUTOFMEMORY;
if (!(conn = calloc( 1, sizeof(*conn) ))) return ERROR_OUTOFMEMORY;
conn->host = host;
conn->sockaddr = *sockaddr;
if ((conn->socket = socket( sockaddr->ss_family, SOCK_STREAM, 0 )) == -1)
{
ret = WSAGetLastError();
WARN("unable to create socket (%u)\n", ret);
heap_free( conn );
free( conn );
return ret;
}
......@@ -208,7 +208,7 @@ DWORD netconn_create( struct hostdata *host, const struct sockaddr_storage *sock
break;
default:
ERR( "unhandled family %u\n", conn->sockaddr.ss_family );
heap_free( conn );
free( conn );
return ERROR_INVALID_PARAMETER;
}
......@@ -237,7 +237,7 @@ DWORD netconn_create( struct hostdata *host, const struct sockaddr_storage *sock
{
WARN("unable to connect to host (%u)\n", ret);
closesocket( conn->socket );
heap_free( conn );
free( conn );
return ret;
}
......@@ -249,14 +249,14 @@ void netconn_close( struct netconn *conn )
{
if (conn->secure)
{
heap_free( conn->peek_msg_mem );
heap_free(conn->ssl_buf);
heap_free(conn->extra_buf);
free( conn->peek_msg_mem );
free(conn->ssl_buf);
free(conn->extra_buf);
DeleteSecurityContext(&conn->ssl_ctx);
}
closesocket( conn->socket );
release_host( conn->host );
heap_free(conn);
free(conn);
}
DWORD netconn_secure_connect( struct netconn *conn, WCHAR *hostname, DWORD security_flags, CredHandle *cred_handle,
......@@ -276,7 +276,7 @@ DWORD netconn_secure_connect( struct netconn *conn, WCHAR *hostname, DWORD secur
const DWORD isc_req_flags = ISC_REQ_ALLOCATE_MEMORY|ISC_REQ_USE_SESSION_KEY|ISC_REQ_CONFIDENTIALITY
|ISC_REQ_SEQUENCE_DETECT|ISC_REQ_REPLAY_DETECT|ISC_REQ_MANUAL_CRED_VALIDATION;
if (!(read_buf = heap_alloc( read_buf_size ))) return ERROR_OUTOFMEMORY;
if (!(read_buf = malloc( read_buf_size ))) return ERROR_OUTOFMEMORY;
status = InitializeSecurityContextW(cred_handle, NULL, hostname, isc_req_flags, 0, 0, NULL, 0,
&ctx, &out_desc, &attrs, NULL);
......@@ -318,7 +318,7 @@ DWORD netconn_secure_connect( struct netconn *conn, WCHAR *hostname, DWORD secur
if(in_bufs[0].cbBuffer + 1024 > read_buf_size) {
BYTE *new_read_buf;
new_read_buf = heap_realloc(read_buf, read_buf_size + 1024);
new_read_buf = realloc(read_buf, read_buf_size + 1024);
if(!new_read_buf) {
status = E_OUTOFMEMORY;
break;
......@@ -365,7 +365,7 @@ DWORD netconn_secure_connect( struct netconn *conn, WCHAR *hostname, DWORD secur
break;
}
conn->ssl_buf = heap_alloc(conn->ssl_sizes.cbHeader + conn->ssl_sizes.cbMaximumMessage + conn->ssl_sizes.cbTrailer);
conn->ssl_buf = malloc(conn->ssl_sizes.cbHeader + conn->ssl_sizes.cbMaximumMessage + conn->ssl_sizes.cbTrailer);
if(!conn->ssl_buf) {
res = ERROR_OUTOFMEMORY;
break;
......@@ -373,11 +373,11 @@ DWORD netconn_secure_connect( struct netconn *conn, WCHAR *hostname, DWORD secur
}
}
heap_free(read_buf);
free(read_buf);
if(status != SEC_E_OK || res != ERROR_SUCCESS) {
WARN("Failed to initialize security context: %08x\n", status);
heap_free(conn->ssl_buf);
free(conn->ssl_buf);
conn->ssl_buf = NULL;
DeleteSecurityContext(&ctx);
return ERROR_WINHTTP_SECURE_CHANNEL_ERROR;
......@@ -459,7 +459,7 @@ static DWORD read_ssl_chunk( struct netconn *conn, void *buf, SIZE_T buf_size, S
memcpy(conn->ssl_buf, conn->extra_buf, conn->extra_len);
buf_len = conn->extra_len;
conn->extra_len = 0;
heap_free(conn->extra_buf);
free(conn->extra_buf);
conn->extra_buf = NULL;
}else {
if ((buf_len = sock_recv( conn->socket, conn->ssl_buf + conn->extra_len, ssl_buf_size - conn->extra_len, 0)) < 0)
......@@ -516,7 +516,7 @@ static DWORD read_ssl_chunk( struct netconn *conn, void *buf, SIZE_T buf_size, S
memcpy(buf, bufs[i].pvBuffer, size);
if(size < bufs[i].cbBuffer) {
assert(!conn->peek_len);
conn->peek_msg_mem = conn->peek_msg = heap_alloc(bufs[i].cbBuffer - size);
conn->peek_msg_mem = conn->peek_msg = malloc(bufs[i].cbBuffer - size);
if(!conn->peek_msg)
return ERROR_OUTOFMEMORY;
conn->peek_len = bufs[i].cbBuffer-size;
......@@ -529,7 +529,7 @@ static DWORD read_ssl_chunk( struct netconn *conn, void *buf, SIZE_T buf_size, S
for(i = 0; i < ARRAY_SIZE(bufs); i++) {
if(bufs[i].BufferType == SECBUFFER_EXTRA) {
conn->extra_buf = heap_alloc(bufs[i].cbBuffer);
conn->extra_buf = malloc(bufs[i].cbBuffer);
if(!conn->extra_buf)
return ERROR_OUTOFMEMORY;
......@@ -561,7 +561,7 @@ DWORD netconn_recv( struct netconn *conn, void *buf, size_t len, int flags, int
if (conn->peek_len == 0)
{
heap_free( conn->peek_msg_mem );
free( conn->peek_msg_mem );
conn->peek_msg_mem = NULL;
conn->peek_msg = NULL;
}
......
......@@ -65,7 +65,7 @@ static WCHAR *decode_url( LPCWSTR url, DWORD *len )
const WCHAR *p = url;
WCHAR hex[3], *q, *ret;
if (!(ret = heap_alloc( *len * sizeof(WCHAR) ))) return NULL;
if (!(ret = malloc( *len * sizeof(WCHAR) ))) return NULL;
q = ret;
while (*len > 0)
{
......@@ -144,7 +144,7 @@ static DWORD escape_url( const WCHAR *url, DWORD *len, WCHAR **ret )
len_path = 0;
}
if (!(*ret = heap_alloc( (len_base + len_path + 1) * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
if (!(*ret = malloc( (len_base + len_path + 1) * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
memcpy( *ret, url, len_base * sizeof(WCHAR) );
if (p) escape_string( p, *len - (p - url), *ret + len_base, &len_path );
......@@ -331,8 +331,8 @@ exit:
if (overflow) err = ERROR_INSUFFICIENT_BUFFER;
uc->nScheme = scheme_number;
}
heap_free( url_decoded );
heap_free( url_escaped );
free( url_decoded );
free( url_escaped );
SetLastError( err );
return !err;
}
......
......@@ -19,13 +19,12 @@
#ifndef _WINE_WINHTTP_PRIVATE_H_
#define _WINE_WINHTTP_PRIVATE_H_
#include "wine/heap.h"
#include "wine/list.h"
#include "ole2.h"
#include "sspi.h"
#include "wincrypt.h"
#include "wine/list.h"
#define WINHTTP_HANDLE_TYPE_SOCKET 4
struct object_header;
......@@ -347,17 +346,12 @@ DWORD process_header( struct request *, const WCHAR *, const WCHAR *, DWORD, BOO
extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN;
void release_typelib( void ) DECLSPEC_HIDDEN;
static inline void* __WINE_ALLOC_SIZE(2) heap_realloc_zero( LPVOID mem, SIZE_T size )
{
return HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, mem, size );
}
static inline WCHAR *strdupW( const WCHAR *src )
{
WCHAR *dst;
if (!src) return NULL;
dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
dst = malloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) );
if (dst) lstrcpyW( dst, src );
return dst;
}
......@@ -368,7 +362,7 @@ static inline WCHAR *strdupAW( const char *src )
if (src)
{
int len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
if ((dst = heap_alloc( len * sizeof(WCHAR) )))
if ((dst = malloc( len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
}
return dst;
......@@ -380,7 +374,7 @@ static inline char *strdupWA( const WCHAR *src )
if (src)
{
int len = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
if ((dst = heap_alloc( len )))
if ((dst = malloc( len )))
WideCharToMultiByte( CP_ACP, 0, src, -1, dst, len, NULL, NULL );
}
return dst;
......@@ -392,7 +386,7 @@ static inline char *strdupWA_sized( const WCHAR *src, DWORD size )
if (src)
{
int len = WideCharToMultiByte( CP_ACP, 0, src, size, NULL, 0, NULL, NULL ) + 1;
if ((dst = heap_alloc( len )))
if ((dst = malloc( len )))
{
WideCharToMultiByte( CP_ACP, 0, src, size, dst, len, NULL, NULL );
dst[len - 1] = 0;
......
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