Commit 7de7f9af authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wldap32: Use the global memory allocation helpers.

parent e76066be
...@@ -276,8 +276,7 @@ INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info, ...@@ -276,8 +276,7 @@ INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
static inline void bv_val_dup( const struct WLDAP32_berval *src, struct WLDAP32_berval *dst ) static inline void bv_val_dup( const struct WLDAP32_berval *src, struct WLDAP32_berval *dst )
{ {
dst->bv_val = HeapAlloc( GetProcessHeap(), 0, src->bv_len ); if ((dst->bv_val = heap_alloc( src->bv_len )))
if (dst->bv_val)
{ {
memcpy( dst->bv_val, src->bv_val, src->bv_len ); memcpy( dst->bv_val, src->bv_val, src->bv_len );
dst->bv_len = src->bv_len; dst->bv_len = src->bv_len;
......
...@@ -62,10 +62,9 @@ static char **split_hostnames( const char *hostnames ) ...@@ -62,10 +62,9 @@ static char **split_hostnames( const char *hostnames )
p++; p++;
} }
res = HeapAlloc( GetProcessHeap(), 0, (i + 1) * sizeof(char *) ); if (!(res = heap_alloc( (i + 1) * sizeof(char *) )))
if (!res)
{ {
HeapFree( GetProcessHeap(), 0, str ); heap_free( str );
return NULL; return NULL;
} }
...@@ -74,7 +73,7 @@ static char **split_hostnames( const char *hostnames ) ...@@ -74,7 +73,7 @@ static char **split_hostnames( const char *hostnames )
q = p; q = p;
i = 0; i = 0;
while (*p) while (*p)
{ {
if (p[1] != '\0') if (p[1] != '\0')
...@@ -85,7 +84,7 @@ static char **split_hostnames( const char *hostnames ) ...@@ -85,7 +84,7 @@ static char **split_hostnames( const char *hostnames )
res[i] = strdupU( q ); res[i] = strdupU( q );
if (!res[i]) goto oom; if (!res[i]) goto oom;
i++; i++;
while (isspace( *p )) p++; while (isspace( *p )) p++;
q = p; q = p;
} }
...@@ -100,14 +99,14 @@ static char **split_hostnames( const char *hostnames ) ...@@ -100,14 +99,14 @@ static char **split_hostnames( const char *hostnames )
} }
res[i] = NULL; res[i] = NULL;
HeapFree( GetProcessHeap(), 0, str ); heap_free( str );
return res; return res;
oom: oom:
while (i > 0) strfreeU( res[--i] ); while (i > 0) strfreeU( res[--i] );
HeapFree( GetProcessHeap(), 0, res ); heap_free( res );
HeapFree( GetProcessHeap(), 0, str ); heap_free( str );
return NULL; return NULL;
} }
...@@ -154,9 +153,7 @@ static char *join_hostnames( const char *scheme, char **hostnames, ULONG portnum ...@@ -154,9 +153,7 @@ static char *join_hostnames( const char *scheme, char **hostnames, ULONG portnum
} }
size += (i - 1) * strlen( sep ); size += (i - 1) * strlen( sep );
if (!(res = heap_alloc( size + 1 ))) return NULL;
res = HeapAlloc( GetProcessHeap(), 0, size + 1 );
if (!res) return NULL;
p = res; p = res;
for (v = hostnames; *v; v++) for (v = hostnames; *v; v++)
......
...@@ -99,17 +99,15 @@ static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie, ...@@ -99,17 +99,15 @@ static ULONG create_page_control( ULONG pagesize, struct WLDAP32_berval *cookie,
return WLDAP32_LDAP_NO_MEMORY; return WLDAP32_LDAP_NO_MEMORY;
/* copy the berval so it can be properly freed by the caller */ /* copy the berval so it can be properly freed by the caller */
val = HeapAlloc( GetProcessHeap(), 0, berval->bv_len ); if (!(val = heap_alloc( berval->bv_len ))) return WLDAP32_LDAP_NO_MEMORY;
if (!val) return WLDAP32_LDAP_NO_MEMORY;
len = berval->bv_len; len = berval->bv_len;
memcpy( val, berval->bv_val, len ); memcpy( val, berval->bv_val, len );
ber_bvfree( berval ); ber_bvfree( berval );
ctrl = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) ); if (!(ctrl = heap_alloc( sizeof(LDAPControlW) )))
if (!ctrl)
{ {
HeapFree( GetProcessHeap(), 0, val ); heap_free( val );
return WLDAP32_LDAP_NO_MEMORY; return WLDAP32_LDAP_NO_MEMORY;
} }
......
...@@ -156,8 +156,7 @@ static char *bv2str( struct berval *bv ) ...@@ -156,8 +156,7 @@ static char *bv2str( struct berval *bv )
char *str = NULL; char *str = NULL;
unsigned int len = bv->bv_len; unsigned int len = bv->bv_len;
str = HeapAlloc( GetProcessHeap(), 0, len + 1 ); if ((str = heap_alloc( len + 1 )))
if (str)
{ {
memcpy( str, bv->bv_val, len ); memcpy( str, bv->bv_val, len );
str[len] = '\0'; str[len] = '\0';
...@@ -176,8 +175,7 @@ static char **bv2str_array( struct berval **bv ) ...@@ -176,8 +175,7 @@ static char **bv2str_array( struct berval **bv )
len++; len++;
p++; p++;
} }
str = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(char *) ); if (!(str = heap_alloc( (len + 1) * sizeof(char *) ))) return NULL;
if (!str) return NULL;
p = bv; p = bv;
while (*p) while (*p)
...@@ -185,8 +183,8 @@ static char **bv2str_array( struct berval **bv ) ...@@ -185,8 +183,8 @@ static char **bv2str_array( struct berval **bv )
str[i] = bv2str( *p ); str[i] = bv2str( *p );
if (!str[i]) if (!str[i])
{ {
while (i > 0) HeapFree( GetProcessHeap(), 0, str[--i] ); while (i > 0) heap_free( str[--i] );
HeapFree( GetProcessHeap(), 0, str ); heap_free( str );
return NULL; return NULL;
} }
i++; i++;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "wine/heap.h"
#include "wine/unicode.h" #include "wine/unicode.h"
extern HINSTANCE hwldap32 DECLSPEC_HIDDEN; extern HINSTANCE hwldap32 DECLSPEC_HIDDEN;
...@@ -31,22 +32,16 @@ ULONG map_error( int ) DECLSPEC_HIDDEN; ...@@ -31,22 +32,16 @@ ULONG map_error( int ) DECLSPEC_HIDDEN;
static inline char *strdupU( const char *src ) static inline char *strdupU( const char *src )
{ {
char *dst; char *dst;
if (!src) return NULL; if (!src) return NULL;
dst = HeapAlloc( GetProcessHeap(), 0, (strlen( src ) + 1) * sizeof(char) ); if ((dst = heap_alloc( (strlen( src ) + 1) * sizeof(char) ))) strcpy( dst, src );
if (dst)
strcpy( dst, src );
return dst; return dst;
} }
static inline WCHAR *strdupW( const WCHAR *src ) static inline WCHAR *strdupW( const WCHAR *src )
{ {
WCHAR *dst; WCHAR *dst;
if (!src) return NULL; if (!src) return NULL;
dst = HeapAlloc( GetProcessHeap(), 0, (strlenW( src ) + 1) * sizeof(WCHAR) ); if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
if (dst)
strcpyW( dst, src );
return dst; return dst;
} }
...@@ -56,7 +51,7 @@ static inline LPWSTR strAtoW( LPCSTR str ) ...@@ -56,7 +51,7 @@ static inline LPWSTR strAtoW( LPCSTR str )
if (str) if (str)
{ {
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 ); DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) if ((ret = heap_alloc( len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len ); MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
} }
return ret; return ret;
...@@ -68,7 +63,7 @@ static inline LPSTR strWtoA( LPCWSTR str ) ...@@ -68,7 +63,7 @@ static inline LPSTR strWtoA( LPCWSTR str )
if (str) if (str)
{ {
DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL ); DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len ))) if ((ret = heap_alloc( len )))
WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL ); WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
} }
return ret; return ret;
...@@ -80,7 +75,7 @@ static inline char *strWtoU( LPCWSTR str ) ...@@ -80,7 +75,7 @@ static inline char *strWtoU( LPCWSTR str )
if (str) if (str)
{ {
DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL ); DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len ))) if ((ret = heap_alloc( len )))
WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL ); WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
} }
return ret; return ret;
...@@ -92,7 +87,7 @@ static inline LPWSTR strUtoW( char *str ) ...@@ -92,7 +87,7 @@ static inline LPWSTR strUtoW( char *str )
if (str) if (str)
{ {
DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 ); DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) if ((ret = heap_alloc( len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len ); MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
} }
return ret; return ret;
...@@ -100,17 +95,17 @@ static inline LPWSTR strUtoW( char *str ) ...@@ -100,17 +95,17 @@ static inline LPWSTR strUtoW( char *str )
static inline void strfreeA( LPSTR str ) static inline void strfreeA( LPSTR str )
{ {
HeapFree( GetProcessHeap(), 0, str ); heap_free( str );
} }
static inline void strfreeW( LPWSTR str ) static inline void strfreeW( LPWSTR str )
{ {
HeapFree( GetProcessHeap(), 0, str ); heap_free( str );
} }
static inline void strfreeU( char *str ) static inline void strfreeU( char *str )
{ {
HeapFree( GetProcessHeap(), 0, str ); heap_free( str );
} }
static inline DWORD strarraylenA( LPSTR *strarray ) static inline DWORD strarraylenA( LPSTR *strarray )
...@@ -142,9 +137,7 @@ static inline LPWSTR *strarrayAtoW( LPSTR *strarray ) ...@@ -142,9 +137,7 @@ static inline LPWSTR *strarrayAtoW( LPSTR *strarray )
if (strarray) if (strarray)
{ {
size = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1); size = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
strarrayW = HeapAlloc( GetProcessHeap(), 0, size ); if ((strarrayW = heap_alloc( size )))
if (strarrayW)
{ {
LPSTR *p = strarray; LPSTR *p = strarray;
LPWSTR *q = strarrayW; LPWSTR *q = strarrayW;
...@@ -164,9 +157,7 @@ static inline LPSTR *strarrayWtoA( LPWSTR *strarray ) ...@@ -164,9 +157,7 @@ static inline LPSTR *strarrayWtoA( LPWSTR *strarray )
if (strarray) if (strarray)
{ {
size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1); size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
strarrayA = HeapAlloc( GetProcessHeap(), 0, size ); if ((strarrayA = heap_alloc( size )))
if (strarrayA)
{ {
LPWSTR *p = strarray; LPWSTR *p = strarray;
LPSTR *q = strarrayA; LPSTR *q = strarrayA;
...@@ -186,9 +177,7 @@ static inline char **strarrayWtoU( LPWSTR *strarray ) ...@@ -186,9 +177,7 @@ static inline char **strarrayWtoU( LPWSTR *strarray )
if (strarray) if (strarray)
{ {
size = sizeof(char*) * (strarraylenW( strarray ) + 1); size = sizeof(char*) * (strarraylenW( strarray ) + 1);
strarrayU = HeapAlloc( GetProcessHeap(), 0, size ); if ((strarrayU = heap_alloc( size )))
if (strarrayU)
{ {
LPWSTR *p = strarray; LPWSTR *p = strarray;
char **q = strarrayU; char **q = strarrayU;
...@@ -208,9 +197,7 @@ static inline LPWSTR *strarrayUtoW( char **strarray ) ...@@ -208,9 +197,7 @@ static inline LPWSTR *strarrayUtoW( char **strarray )
if (strarray) if (strarray)
{ {
size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1); size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
strarrayW = HeapAlloc( GetProcessHeap(), 0, size ); if ((strarrayW = heap_alloc( size )))
if (strarrayW)
{ {
char **p = strarray; char **p = strarray;
LPWSTR *q = strarrayW; LPWSTR *q = strarrayW;
...@@ -228,7 +215,7 @@ static inline void strarrayfreeA( LPSTR *strarray ) ...@@ -228,7 +215,7 @@ static inline void strarrayfreeA( LPSTR *strarray )
{ {
LPSTR *p = strarray; LPSTR *p = strarray;
while (*p) strfreeA( *p++ ); while (*p) strfreeA( *p++ );
HeapFree( GetProcessHeap(), 0, strarray ); heap_free( strarray );
} }
} }
...@@ -238,7 +225,7 @@ static inline void strarrayfreeW( LPWSTR *strarray ) ...@@ -238,7 +225,7 @@ static inline void strarrayfreeW( LPWSTR *strarray )
{ {
LPWSTR *p = strarray; LPWSTR *p = strarray;
while (*p) strfreeW( *p++ ); while (*p) strfreeW( *p++ );
HeapFree( GetProcessHeap(), 0, strarray ); heap_free( strarray );
} }
} }
...@@ -248,7 +235,7 @@ static inline void strarrayfreeU( char **strarray ) ...@@ -248,7 +235,7 @@ static inline void strarrayfreeU( char **strarray )
{ {
char **p = strarray; char **p = strarray;
while (*p) strfreeU( *p++ ); while (*p) strfreeU( *p++ );
HeapFree( GetProcessHeap(), 0, strarray ); heap_free( strarray );
} }
} }
...@@ -259,8 +246,7 @@ static inline struct berval *bvdup( struct berval *bv ) ...@@ -259,8 +246,7 @@ static inline struct berval *bvdup( struct berval *bv )
struct berval *berval; struct berval *berval;
DWORD size = sizeof(struct berval) + bv->bv_len; DWORD size = sizeof(struct berval) + bv->bv_len;
berval = HeapAlloc( GetProcessHeap(), 0, size ); if ((berval = heap_alloc( size )))
if (berval)
{ {
char *val = (char *)berval + sizeof(struct berval); char *val = (char *)berval + sizeof(struct berval);
...@@ -286,9 +272,7 @@ static inline struct berval **bvarraydup( struct berval **bv ) ...@@ -286,9 +272,7 @@ static inline struct berval **bvarraydup( struct berval **bv )
if (bv) if (bv)
{ {
size = sizeof(struct berval *) * (bvarraylen( bv ) + 1); size = sizeof(struct berval *) * (bvarraylen( bv ) + 1);
berval = HeapAlloc( GetProcessHeap(), 0, size ); if ((berval = heap_alloc( size )))
if (berval)
{ {
struct berval **p = bv; struct berval **p = bv;
struct berval **q = berval; struct berval **q = berval;
...@@ -303,16 +287,15 @@ static inline struct berval **bvarraydup( struct berval **bv ) ...@@ -303,16 +287,15 @@ static inline struct berval **bvarraydup( struct berval **bv )
static inline void bvarrayfree( struct berval **bv ) static inline void bvarrayfree( struct berval **bv )
{ {
struct berval **p = bv; struct berval **p = bv;
while (*p) HeapFree( GetProcessHeap(), 0, *p++ ); while (*p) heap_free( *p++ );
HeapFree( GetProcessHeap(), 0, bv ); heap_free( bv );
} }
static inline LDAPModW *modAtoW( LDAPModA *mod ) static inline LDAPModW *modAtoW( LDAPModA *mod )
{ {
LDAPModW *modW; LDAPModW *modW;
modW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPModW) ); if ((modW = heap_alloc( sizeof(LDAPModW) )))
if (modW)
{ {
modW->mod_op = mod->mod_op; modW->mod_op = mod->mod_op;
modW->mod_type = strAtoW( mod->mod_type ); modW->mod_type = strAtoW( mod->mod_type );
...@@ -329,8 +312,7 @@ static inline LDAPMod *modWtoU( LDAPModW *mod ) ...@@ -329,8 +312,7 @@ static inline LDAPMod *modWtoU( LDAPModW *mod )
{ {
LDAPMod *modU; LDAPMod *modU;
modU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPMod) ); if ((modU = heap_alloc( sizeof(LDAPMod) )))
if (modU)
{ {
modU->mod_op = mod->mod_op; modU->mod_op = mod->mod_op;
modU->mod_type = strWtoU( mod->mod_type ); modU->mod_type = strWtoU( mod->mod_type );
...@@ -349,7 +331,7 @@ static inline void modfreeW( LDAPModW *mod ) ...@@ -349,7 +331,7 @@ static inline void modfreeW( LDAPModW *mod )
bvarrayfree( mod->mod_vals.modv_bvals ); bvarrayfree( mod->mod_vals.modv_bvals );
else else
strarrayfreeW( mod->mod_vals.modv_strvals ); strarrayfreeW( mod->mod_vals.modv_strvals );
HeapFree( GetProcessHeap(), 0, mod ); heap_free( mod );
} }
static inline void modfreeU( LDAPMod *mod ) static inline void modfreeU( LDAPMod *mod )
...@@ -358,7 +340,7 @@ static inline void modfreeU( LDAPMod *mod ) ...@@ -358,7 +340,7 @@ static inline void modfreeU( LDAPMod *mod )
bvarrayfree( mod->mod_vals.modv_bvals ); bvarrayfree( mod->mod_vals.modv_bvals );
else else
strarrayfreeU( mod->mod_vals.modv_strvals ); strarrayfreeU( mod->mod_vals.modv_strvals );
HeapFree( GetProcessHeap(), 0, mod ); heap_free( mod );
} }
static inline DWORD modarraylenA( LDAPModA **modarray ) static inline DWORD modarraylenA( LDAPModA **modarray )
...@@ -383,9 +365,7 @@ static inline LDAPModW **modarrayAtoW( LDAPModA **modarray ) ...@@ -383,9 +365,7 @@ static inline LDAPModW **modarrayAtoW( LDAPModA **modarray )
if (modarray) if (modarray)
{ {
size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1); size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
modarrayW = HeapAlloc( GetProcessHeap(), 0, size ); if ((modarrayW = heap_alloc( size )))
if (modarrayW)
{ {
LDAPModA **p = modarray; LDAPModA **p = modarray;
LDAPModW **q = modarrayW; LDAPModW **q = modarrayW;
...@@ -405,9 +385,7 @@ static inline LDAPMod **modarrayWtoU( LDAPModW **modarray ) ...@@ -405,9 +385,7 @@ static inline LDAPMod **modarrayWtoU( LDAPModW **modarray )
if (modarray) if (modarray)
{ {
size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1); size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
modarrayU = HeapAlloc( GetProcessHeap(), 0, size ); if ((modarrayU = heap_alloc( size )))
if (modarrayU)
{ {
LDAPModW **p = modarray; LDAPModW **p = modarray;
LDAPMod **q = modarrayU; LDAPMod **q = modarrayU;
...@@ -425,7 +403,7 @@ static inline void modarrayfreeW( LDAPModW **modarray ) ...@@ -425,7 +403,7 @@ static inline void modarrayfreeW( LDAPModW **modarray )
{ {
LDAPModW **p = modarray; LDAPModW **p = modarray;
while (*p) modfreeW( *p++ ); while (*p) modfreeW( *p++ );
HeapFree( GetProcessHeap(), 0, modarray ); heap_free( modarray );
} }
} }
...@@ -435,7 +413,7 @@ static inline void modarrayfreeU( LDAPMod **modarray ) ...@@ -435,7 +413,7 @@ static inline void modarrayfreeU( LDAPMod **modarray )
{ {
LDAPMod **p = modarray; LDAPMod **p = modarray;
while (*p) modfreeU( *p++ ); while (*p) modfreeU( *p++ );
HeapFree( GetProcessHeap(), 0, modarray ); heap_free( modarray );
} }
} }
...@@ -447,15 +425,13 @@ static inline LDAPControlW *controlAtoW( LDAPControlA *control ) ...@@ -447,15 +425,13 @@ static inline LDAPControlW *controlAtoW( LDAPControlA *control )
if (control->ldctl_value.bv_val) if (control->ldctl_value.bv_val)
{ {
val = HeapAlloc( GetProcessHeap(), 0, len ); if (!(val = heap_alloc( len ))) return NULL;
if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len ); memcpy( val, control->ldctl_value.bv_val, len );
} }
controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) ); if (!(controlW = heap_alloc( sizeof(LDAPControlW) )))
if (!controlW)
{ {
HeapFree( GetProcessHeap(), 0, val ); heap_free( val );
return NULL; return NULL;
} }
...@@ -475,15 +451,13 @@ static inline LDAPControlA *controlWtoA( LDAPControlW *control ) ...@@ -475,15 +451,13 @@ static inline LDAPControlA *controlWtoA( LDAPControlW *control )
if (control->ldctl_value.bv_val) if (control->ldctl_value.bv_val)
{ {
val = HeapAlloc( GetProcessHeap(), 0, len ); if (!(val = heap_alloc( len ))) return NULL;
if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len ); memcpy( val, control->ldctl_value.bv_val, len );
} }
controlA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlA) ); if (!(controlA = heap_alloc( sizeof(LDAPControlA) )))
if (!controlA)
{ {
HeapFree( GetProcessHeap(), 0, val ); heap_free( val );
return NULL; return NULL;
} }
...@@ -503,15 +477,13 @@ static inline LDAPControl *controlWtoU( LDAPControlW *control ) ...@@ -503,15 +477,13 @@ static inline LDAPControl *controlWtoU( LDAPControlW *control )
if (control->ldctl_value.bv_val) if (control->ldctl_value.bv_val)
{ {
val = HeapAlloc( GetProcessHeap(), 0, len ); if (!(val = heap_alloc( len ))) return NULL;
if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len ); memcpy( val, control->ldctl_value.bv_val, len );
} }
controlU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) ); if (!(controlU = heap_alloc( sizeof(LDAPControl) )))
if (!controlU)
{ {
HeapFree( GetProcessHeap(), 0, val ); heap_free( val );
return NULL; return NULL;
} }
...@@ -531,15 +503,13 @@ static inline LDAPControlW *controlUtoW( LDAPControl *control ) ...@@ -531,15 +503,13 @@ static inline LDAPControlW *controlUtoW( LDAPControl *control )
if (control->ldctl_value.bv_val) if (control->ldctl_value.bv_val)
{ {
val = HeapAlloc( GetProcessHeap(), 0, len ); if (!(val = heap_alloc( len ))) return NULL;
if (!val) return NULL;
memcpy( val, control->ldctl_value.bv_val, len ); memcpy( val, control->ldctl_value.bv_val, len );
} }
controlW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) ); if (!(controlW = heap_alloc( sizeof(LDAPControlW) )))
if (!controlW)
{ {
HeapFree( GetProcessHeap(), 0, val ); heap_free( val );
return NULL; return NULL;
} }
...@@ -547,7 +517,7 @@ static inline LDAPControlW *controlUtoW( LDAPControl *control ) ...@@ -547,7 +517,7 @@ static inline LDAPControlW *controlUtoW( LDAPControl *control )
controlW->ldctl_value.bv_len = len; controlW->ldctl_value.bv_len = len;
controlW->ldctl_value.bv_val = val; controlW->ldctl_value.bv_val = val;
controlW->ldctl_iscritical = control->ldctl_iscritical; controlW->ldctl_iscritical = control->ldctl_iscritical;
return controlW; return controlW;
} }
...@@ -556,8 +526,8 @@ static inline void controlfreeA( LDAPControlA *control ) ...@@ -556,8 +526,8 @@ static inline void controlfreeA( LDAPControlA *control )
if (control) if (control)
{ {
strfreeA( control->ldctl_oid ); strfreeA( control->ldctl_oid );
HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val ); heap_free( control->ldctl_value.bv_val );
HeapFree( GetProcessHeap(), 0, control ); heap_free( control );
} }
} }
...@@ -566,8 +536,8 @@ static inline void controlfreeW( LDAPControlW *control ) ...@@ -566,8 +536,8 @@ static inline void controlfreeW( LDAPControlW *control )
if (control) if (control)
{ {
strfreeW( control->ldctl_oid ); strfreeW( control->ldctl_oid );
HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val ); heap_free( control->ldctl_value.bv_val );
HeapFree( GetProcessHeap(), 0, control ); heap_free( control );
} }
} }
...@@ -576,8 +546,8 @@ static inline void controlfreeU( LDAPControl *control ) ...@@ -576,8 +546,8 @@ static inline void controlfreeU( LDAPControl *control )
if (control) if (control)
{ {
strfreeU( control->ldctl_oid ); strfreeU( control->ldctl_oid );
HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val ); heap_free( control->ldctl_value.bv_val );
HeapFree( GetProcessHeap(), 0, control ); heap_free( control );
} }
} }
...@@ -610,9 +580,7 @@ static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray ) ...@@ -610,9 +580,7 @@ static inline LDAPControlW **controlarrayAtoW( LDAPControlA **controlarray )
if (controlarray) if (controlarray)
{ {
size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1); size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
controlarrayW = HeapAlloc( GetProcessHeap(), 0, size ); if ((controlarrayW = heap_alloc( size )))
if (controlarrayW)
{ {
LDAPControlA **p = controlarray; LDAPControlA **p = controlarray;
LDAPControlW **q = controlarrayW; LDAPControlW **q = controlarrayW;
...@@ -632,9 +600,7 @@ static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray ) ...@@ -632,9 +600,7 @@ static inline LDAPControlA **controlarrayWtoA( LDAPControlW **controlarray )
if (controlarray) if (controlarray)
{ {
size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1); size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
controlarrayA = HeapAlloc( GetProcessHeap(), 0, size ); if ((controlarrayA = heap_alloc( size )))
if (controlarrayA)
{ {
LDAPControlW **p = controlarray; LDAPControlW **p = controlarray;
LDAPControlA **q = controlarrayA; LDAPControlA **q = controlarrayA;
...@@ -654,9 +620,7 @@ static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray ) ...@@ -654,9 +620,7 @@ static inline LDAPControl **controlarrayWtoU( LDAPControlW **controlarray )
if (controlarray) if (controlarray)
{ {
size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1); size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
controlarrayU = HeapAlloc( GetProcessHeap(), 0, size ); if ((controlarrayU = heap_alloc( size )))
if (controlarrayU)
{ {
LDAPControlW **p = controlarray; LDAPControlW **p = controlarray;
LDAPControl **q = controlarrayU; LDAPControl **q = controlarrayU;
...@@ -676,9 +640,7 @@ static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray ) ...@@ -676,9 +640,7 @@ static inline LDAPControlW **controlarrayUtoW( LDAPControl **controlarray )
if (controlarray) if (controlarray)
{ {
size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1); size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
controlarrayW = HeapAlloc( GetProcessHeap(), 0, size ); if ((controlarrayW = heap_alloc( size )))
if (controlarrayW)
{ {
LDAPControl **p = controlarray; LDAPControl **p = controlarray;
LDAPControlW **q = controlarrayW; LDAPControlW **q = controlarrayW;
...@@ -696,7 +658,7 @@ static inline void controlarrayfreeA( LDAPControlA **controlarray ) ...@@ -696,7 +658,7 @@ static inline void controlarrayfreeA( LDAPControlA **controlarray )
{ {
LDAPControlA **p = controlarray; LDAPControlA **p = controlarray;
while (*p) controlfreeA( *p++ ); while (*p) controlfreeA( *p++ );
HeapFree( GetProcessHeap(), 0, controlarray ); heap_free( controlarray );
} }
} }
...@@ -706,7 +668,7 @@ static inline void controlarrayfreeW( LDAPControlW **controlarray ) ...@@ -706,7 +668,7 @@ static inline void controlarrayfreeW( LDAPControlW **controlarray )
{ {
LDAPControlW **p = controlarray; LDAPControlW **p = controlarray;
while (*p) controlfreeW( *p++ ); while (*p) controlfreeW( *p++ );
HeapFree( GetProcessHeap(), 0, controlarray ); heap_free( controlarray );
} }
} }
...@@ -716,7 +678,7 @@ static inline void controlarrayfreeU( LDAPControl **controlarray ) ...@@ -716,7 +678,7 @@ static inline void controlarrayfreeU( LDAPControl **controlarray )
{ {
LDAPControl **p = controlarray; LDAPControl **p = controlarray;
while (*p) controlfreeU( *p++ ); while (*p) controlfreeU( *p++ );
HeapFree( GetProcessHeap(), 0, controlarray ); heap_free( controlarray );
} }
} }
...@@ -724,8 +686,7 @@ static inline LDAPSortKeyW *sortkeyAtoW( LDAPSortKeyA *sortkey ) ...@@ -724,8 +686,7 @@ static inline LDAPSortKeyW *sortkeyAtoW( LDAPSortKeyA *sortkey )
{ {
LDAPSortKeyW *sortkeyW; LDAPSortKeyW *sortkeyW;
sortkeyW = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyW) ); if ((sortkeyW = heap_alloc( sizeof(LDAPSortKeyW) )))
if (sortkeyW)
{ {
sortkeyW->sk_attrtype = strAtoW( sortkey->sk_attrtype ); sortkeyW->sk_attrtype = strAtoW( sortkey->sk_attrtype );
sortkeyW->sk_matchruleoid = strAtoW( sortkey->sk_matchruleoid ); sortkeyW->sk_matchruleoid = strAtoW( sortkey->sk_matchruleoid );
...@@ -738,8 +699,7 @@ static inline LDAPSortKeyA *sortkeyWtoA( LDAPSortKeyW *sortkey ) ...@@ -738,8 +699,7 @@ static inline LDAPSortKeyA *sortkeyWtoA( LDAPSortKeyW *sortkey )
{ {
LDAPSortKeyA *sortkeyA; LDAPSortKeyA *sortkeyA;
sortkeyA = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKeyA) ); if ((sortkeyA = heap_alloc( sizeof(LDAPSortKeyA) )))
if (sortkeyA)
{ {
sortkeyA->sk_attrtype = strWtoA( sortkey->sk_attrtype ); sortkeyA->sk_attrtype = strWtoA( sortkey->sk_attrtype );
sortkeyA->sk_matchruleoid = strWtoA( sortkey->sk_matchruleoid ); sortkeyA->sk_matchruleoid = strWtoA( sortkey->sk_matchruleoid );
...@@ -752,8 +712,7 @@ static inline LDAPSortKey *sortkeyWtoU( LDAPSortKeyW *sortkey ) ...@@ -752,8 +712,7 @@ static inline LDAPSortKey *sortkeyWtoU( LDAPSortKeyW *sortkey )
{ {
LDAPSortKey *sortkeyU; LDAPSortKey *sortkeyU;
sortkeyU = HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPSortKey) ); if ((sortkeyU = heap_alloc( sizeof(LDAPSortKey) )))
if (sortkeyU)
{ {
sortkeyU->attributeType = strWtoU( sortkey->sk_attrtype ); sortkeyU->attributeType = strWtoU( sortkey->sk_attrtype );
sortkeyU->orderingRule = strWtoU( sortkey->sk_matchruleoid ); sortkeyU->orderingRule = strWtoU( sortkey->sk_matchruleoid );
...@@ -768,7 +727,7 @@ static inline void sortkeyfreeA( LDAPSortKeyA *sortkey ) ...@@ -768,7 +727,7 @@ static inline void sortkeyfreeA( LDAPSortKeyA *sortkey )
{ {
strfreeA( sortkey->sk_attrtype ); strfreeA( sortkey->sk_attrtype );
strfreeA( sortkey->sk_matchruleoid ); strfreeA( sortkey->sk_matchruleoid );
HeapFree( GetProcessHeap(), 0, sortkey ); heap_free( sortkey );
} }
} }
...@@ -778,7 +737,7 @@ static inline void sortkeyfreeW( LDAPSortKeyW *sortkey ) ...@@ -778,7 +737,7 @@ static inline void sortkeyfreeW( LDAPSortKeyW *sortkey )
{ {
strfreeW( sortkey->sk_attrtype ); strfreeW( sortkey->sk_attrtype );
strfreeW( sortkey->sk_matchruleoid ); strfreeW( sortkey->sk_matchruleoid );
HeapFree( GetProcessHeap(), 0, sortkey ); heap_free( sortkey );
} }
} }
...@@ -788,7 +747,7 @@ static inline void sortkeyfreeU( LDAPSortKey *sortkey ) ...@@ -788,7 +747,7 @@ static inline void sortkeyfreeU( LDAPSortKey *sortkey )
{ {
strfreeU( sortkey->attributeType ); strfreeU( sortkey->attributeType );
strfreeU( sortkey->orderingRule ); strfreeU( sortkey->orderingRule );
HeapFree( GetProcessHeap(), 0, sortkey ); heap_free( sortkey );
} }
} }
...@@ -814,9 +773,7 @@ static inline LDAPSortKeyW **sortkeyarrayAtoW( LDAPSortKeyA **sortkeyarray ) ...@@ -814,9 +773,7 @@ static inline LDAPSortKeyW **sortkeyarrayAtoW( LDAPSortKeyA **sortkeyarray )
if (sortkeyarray) if (sortkeyarray)
{ {
size = sizeof(LDAPSortKeyW*) * (sortkeyarraylenA( sortkeyarray ) + 1); size = sizeof(LDAPSortKeyW*) * (sortkeyarraylenA( sortkeyarray ) + 1);
sortkeyarrayW = HeapAlloc( GetProcessHeap(), 0, size ); if ((sortkeyarrayW = heap_alloc( size )))
if (sortkeyarrayW)
{ {
LDAPSortKeyA **p = sortkeyarray; LDAPSortKeyA **p = sortkeyarray;
LDAPSortKeyW **q = sortkeyarrayW; LDAPSortKeyW **q = sortkeyarrayW;
...@@ -836,9 +793,7 @@ static inline LDAPSortKey **sortkeyarrayWtoU( LDAPSortKeyW **sortkeyarray ) ...@@ -836,9 +793,7 @@ static inline LDAPSortKey **sortkeyarrayWtoU( LDAPSortKeyW **sortkeyarray )
if (sortkeyarray) if (sortkeyarray)
{ {
size = sizeof(LDAPSortKey*) * (sortkeyarraylenW( sortkeyarray ) + 1); size = sizeof(LDAPSortKey*) * (sortkeyarraylenW( sortkeyarray ) + 1);
sortkeyarrayU = HeapAlloc( GetProcessHeap(), 0, size ); if ((sortkeyarrayU = heap_alloc( size )))
if (sortkeyarrayU)
{ {
LDAPSortKeyW **p = sortkeyarray; LDAPSortKeyW **p = sortkeyarray;
LDAPSortKey **q = sortkeyarrayU; LDAPSortKey **q = sortkeyarrayU;
...@@ -856,7 +811,7 @@ static inline void sortkeyarrayfreeW( LDAPSortKeyW **sortkeyarray ) ...@@ -856,7 +811,7 @@ static inline void sortkeyarrayfreeW( LDAPSortKeyW **sortkeyarray )
{ {
LDAPSortKeyW **p = sortkeyarray; LDAPSortKeyW **p = sortkeyarray;
while (*p) sortkeyfreeW( *p++ ); while (*p) sortkeyfreeW( *p++ );
HeapFree( GetProcessHeap(), 0, sortkeyarray ); heap_free( sortkeyarray );
} }
} }
...@@ -866,7 +821,7 @@ static inline void sortkeyarrayfreeU( LDAPSortKey **sortkeyarray ) ...@@ -866,7 +821,7 @@ static inline void sortkeyarrayfreeU( LDAPSortKey **sortkeyarray )
{ {
LDAPSortKey **p = sortkeyarray; LDAPSortKey **p = sortkeyarray;
while (*p) sortkeyfreeU( *p++ ); while (*p) sortkeyfreeU( *p++ );
HeapFree( GetProcessHeap(), 0, sortkeyarray ); heap_free( sortkeyarray );
} }
} }
#endif /* HAVE_LDAP */ #endif /* HAVE_LDAP */
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