1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-08 03:45:57 +00:00

wmiutils: Use CRT allocation functions.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2022-09-02 09:19:20 +03:00 committed by Alexandre Julliard
parent e0ca118f03
commit 0e06db3964
3 changed files with 73 additions and 83 deletions

View File

@ -91,7 +91,7 @@ static ULONG WINAPI keylist_Release(
{
TRACE("destroying %p\n", keylist);
IWbemPath_Release( keylist->parent );
heap_free( keylist );
free( keylist );
}
return refs;
}
@ -204,10 +204,10 @@ static void free_keys( struct key *keys, unsigned int count )
for (i = 0; i < count; i++)
{
heap_free( keys[i].name );
heap_free( keys[i].value );
free( keys[i].name );
free( keys[i].value );
}
heap_free( keys );
free( keys );
}
static HRESULT WINAPI keylist_RemoveAllKeys(
@ -281,7 +281,7 @@ static HRESULT WbemPathKeyList_create( IWbemPath *parent, LPVOID *ppObj )
TRACE("%p\n", ppObj);
if (!(keylist = heap_alloc( sizeof(*keylist) ))) return E_OUTOFMEMORY;
if (!(keylist = calloc( 1, sizeof(*keylist) ))) return E_OUTOFMEMORY;
keylist->IWbemPathKeyList_iface.lpVtbl = &keylist_vtbl;
keylist->refs = 1;
@ -314,12 +314,12 @@ static void clear_path( struct path *path )
{
unsigned int i;
heap_free( path->text );
heap_free( path->server );
for (i = 0; i < path->num_namespaces; i++) heap_free( path->namespaces[i] );
heap_free( path->namespaces );
heap_free( path->len_namespaces );
heap_free( path->class );
free( path->text );
free( path->server );
for (i = 0; i < path->num_namespaces; i++) free( path->namespaces[i] );
free( path->namespaces );
free( path->len_namespaces );
free( path->class );
free_keys( path->keys, path->num_keys );
init_path( path );
}
@ -342,7 +342,7 @@ static ULONG WINAPI path_Release(
clear_path( path );
path->cs.DebugInfo->Spare[0] = 0;
DeleteCriticalSection( &path->cs );
heap_free( path );
free( path );
}
return refs;
}
@ -382,7 +382,7 @@ static HRESULT parse_key( struct key *key, const WCHAR *str, unsigned int *ret_l
q++;
}
len = q - p;
if (!(key->name = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
if (!(key->name = malloc( (len + 1) * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
memcpy( key->name, p, len * sizeof(WCHAR) );
key->name[len] = 0;
key->len_name = len;
@ -392,7 +392,7 @@ static HRESULT parse_key( struct key *key, const WCHAR *str, unsigned int *ret_l
while (*q && *q != ',') q++;
len = q - p;
if (!(key->value = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
if (!(key->value = malloc( (len + 1) * sizeof(WCHAR) ))) return E_OUTOFMEMORY;
memcpy( key->value, p, len * sizeof(WCHAR) );
key->value[len] = 0;
key->len_value = len;
@ -415,7 +415,7 @@ static HRESULT parse_text( struct path *path, ULONG mode, const WCHAR *text )
q = p;
while (*q && *q != '\\' && *q != '/') q++;
len = q - p;
if (!(path->server = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto done;
if (!(path->server = malloc( (len + 1) * sizeof(WCHAR) ))) goto done;
memcpy( path->server, p, len * sizeof(WCHAR) );
path->server[len] = 0;
path->len_server = len;
@ -437,8 +437,8 @@ static HRESULT parse_text( struct path *path, ULONG mode, const WCHAR *text )
}
if (path->num_namespaces)
{
if (!(path->namespaces = heap_alloc( path->num_namespaces * sizeof(WCHAR *) ))) goto done;
if (!(path->len_namespaces = heap_alloc( path->num_namespaces * sizeof(int) ))) goto done;
if (!(path->namespaces = malloc( path->num_namespaces * sizeof(WCHAR *) ))) goto done;
if (!(path->len_namespaces = malloc( path->num_namespaces * sizeof(int) ))) goto done;
i = 0;
q = p;
@ -447,7 +447,7 @@ static HRESULT parse_text( struct path *path, ULONG mode, const WCHAR *text )
p = q;
while (*p && *p != '\\' && *p != '/' && *p != ':') p++;
len = p - q;
if (!(path->namespaces[i] = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto done;
if (!(path->namespaces[i] = malloc( (len + 1) * sizeof(WCHAR) ))) goto done;
memcpy( path->namespaces[i], q, len * sizeof(WCHAR) );
path->namespaces[i][len] = 0;
path->len_namespaces[i] = len;
@ -461,7 +461,7 @@ static HRESULT parse_text( struct path *path, ULONG mode, const WCHAR *text )
p = q + 1;
while (*p && *p != '\\' && *p != '/' && *p != ':') p++;
len = p - q - 1;
if (!(path->namespaces[i] = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto done;
if (!(path->namespaces[i] = malloc( (len + 1) * sizeof(WCHAR) ))) goto done;
memcpy( path->namespaces[i], q + 1, len * sizeof(WCHAR) );
path->namespaces[i][len] = 0;
path->len_namespaces[i] = len;
@ -474,7 +474,7 @@ static HRESULT parse_text( struct path *path, ULONG mode, const WCHAR *text )
p = q;
while (*q && *q != '.') q++;
len = q - p;
if (!(path->class = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto done;
if (!(path->class = malloc( (len + 1) * sizeof(WCHAR) ))) goto done;
memcpy( path->class, p, len * sizeof(WCHAR) );
path->class[len] = 0;
path->len_class = len;
@ -488,7 +488,7 @@ static HRESULT parse_text( struct path *path, ULONG mode, const WCHAR *text )
if (*q == ',') path->num_keys++;
q++;
}
if (!(path->keys = heap_alloc_zero( path->num_keys * sizeof(struct key) ))) goto done;
if (!(path->keys = calloc( path->num_keys, sizeof(struct key) ))) goto done;
i = 0;
q = p;
while (*q)
@ -528,7 +528,7 @@ static HRESULT WINAPI path_SetText(
if ((hr = parse_text( path, uMode, pszPath )) != S_OK) goto done;
len = lstrlenW( pszPath );
if (!(path->text = heap_alloc( (len + 1) * sizeof(WCHAR) )))
if (!(path->text = malloc( (len + 1) * sizeof(WCHAR) )))
{
clear_path( path );
hr = E_OUTOFMEMORY;
@ -553,7 +553,7 @@ static WCHAR *build_namespace( struct path *path, int *len, BOOL leading_slash )
if (i > 0 || leading_slash) *len += 1;
*len += path->len_namespaces[i];
}
if (!(p = ret = heap_alloc( (*len + 1) * sizeof(WCHAR) ))) return NULL;
if (!(p = ret = malloc( (*len + 1) * sizeof(WCHAR) ))) return NULL;
for (i = 0; i < path->num_namespaces; i++)
{
if (i > 0 || leading_slash) *p++ = '\\';
@ -571,7 +571,7 @@ static WCHAR *build_server( struct path *path, int *len )
*len = 0;
if (path->len_server) *len += 2 + path->len_server;
else *len += 3;
if (!(p = ret = heap_alloc( (*len + 1) * sizeof(WCHAR) ))) return NULL;
if (!(p = ret = malloc( (*len + 1) * sizeof(WCHAR) ))) return NULL;
if (path->len_server)
{
p[0] = p[1] = '\\';
@ -597,7 +597,7 @@ static WCHAR *build_keylist( struct path *path, int *len )
if (i > 0) *len += 1;
*len += path->keys[i].len_name + path->keys[i].len_value + 1;
}
if (!(p = ret = heap_alloc( (*len + 1) * sizeof(WCHAR) ))) return NULL;
if (!(p = ret = malloc( (*len + 1) * sizeof(WCHAR) ))) return NULL;
for (i = 0; i < path->num_keys; i++)
{
if (i > 0) *p++ = ',';
@ -624,8 +624,8 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
if (!namespace || !keylist)
{
heap_free( namespace );
heap_free( keylist );
free( namespace );
free( keylist );
return NULL;
}
*len = len_namespace;
@ -634,10 +634,10 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
*len += path->len_class + 1;
if (path->num_keys) *len += len_keylist + 1;
}
if (!(ret = heap_alloc( (*len + 1) * sizeof(WCHAR) )))
if (!(ret = malloc( (*len + 1) * sizeof(WCHAR) )))
{
heap_free( namespace );
heap_free( keylist );
free( namespace );
free( keylist );
return NULL;
}
lstrcpyW( ret, namespace );
@ -651,8 +651,8 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
lstrcpyW( ret + len_namespace + path->len_class + 2, keylist );
}
}
heap_free( namespace );
heap_free( keylist );
free( namespace );
free( keylist );
return ret;
}
@ -666,9 +666,9 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
*len = path->len_class;
if (path->num_keys) *len += len_keylist + 1;
if (!(ret = heap_alloc( (*len + 1) * sizeof(WCHAR) )))
if (!(ret = malloc( (*len + 1) * sizeof(WCHAR) )))
{
heap_free( keylist );
free( keylist );
return NULL;
}
lstrcpyW( ret, path->class );
@ -677,7 +677,7 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
ret[path->len_class] = '.';
lstrcpyW( ret + path->len_class + 1, keylist );
}
heap_free( keylist );
free( keylist );
return ret;
}
case WBEMPATH_GET_SERVER_TOO:
@ -689,9 +689,9 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
if (!namespace || !server || !keylist)
{
heap_free( namespace );
heap_free( server );
heap_free( keylist );
free( namespace );
free( server );
free( keylist );
return NULL;
}
*len = len_namespace + len_server;
@ -700,11 +700,11 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
*len += path->len_class + 1;
if (path->num_keys) *len += len_keylist + 1;
}
if (!(p = ret = heap_alloc( (*len + 1) * sizeof(WCHAR) )))
if (!(p = ret = malloc( (*len + 1) * sizeof(WCHAR) )))
{
heap_free( namespace );
heap_free( server );
heap_free( keylist );
free( namespace );
free( server );
free( keylist );
return NULL;
}
lstrcpyW( p, server );
@ -721,9 +721,9 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
lstrcpyW( p + path->len_class + 1, keylist );
}
}
heap_free( namespace );
heap_free( server );
heap_free( keylist );
free( namespace );
free( server );
free( keylist );
return ret;
}
case WBEMPATH_GET_SERVER_AND_NAMESPACE_ONLY:
@ -734,22 +734,22 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
if (!namespace || !server)
{
heap_free( namespace );
heap_free( server );
free( namespace );
free( server );
return NULL;
}
*len = len_namespace + len_server;
if (!(p = ret = heap_alloc( (*len + 1) * sizeof(WCHAR) )))
if (!(p = ret = malloc( (*len + 1) * sizeof(WCHAR) )))
{
heap_free( namespace );
heap_free( server );
free( namespace );
free( server );
return NULL;
}
lstrcpyW( p, server );
p += len_server;
lstrcpyW( p, namespace );
heap_free( namespace );
heap_free( server );
free( namespace );
free( server );
return ret;
}
case WBEMPATH_GET_NAMESPACE_ONLY:
@ -758,7 +758,7 @@ static WCHAR *build_path( struct path *path, LONG flags, int *len )
case WBEMPATH_GET_ORIGINAL:
if (!path->len_text) return NULL;
*len = path->len_text;
return strdupW( path->text );
return wcsdup( path->text );
default:
ERR( "unhandled flags %#lx\n", flags );
@ -801,7 +801,7 @@ static HRESULT WINAPI path_GetText(
TRACE("returning %s\n", debugstr_w(pszText));
done:
heap_free( str );
free( str );
LeaveCriticalSection( &path->cs );
return hr;
}
@ -858,19 +858,19 @@ static HRESULT WINAPI path_SetServer(
if (name)
{
if (!(server = strdupW( name )))
if (!(server = wcsdup( name )))
{
LeaveCriticalSection( &path->cs );
return WBEM_E_OUT_OF_MEMORY;
}
heap_free( path->server );
free( path->server );
path->server = server;
path->len_server = lstrlenW( path->server );
path->flags |= flags;
}
else
{
heap_free( path->server );
free( path->server );
path->server = NULL;
path->len_server = 0;
path->flags &= ~flags;
@ -943,27 +943,27 @@ static HRESULT WINAPI path_SetNamespaceAt(
LeaveCriticalSection( &path->cs );
return WBEM_E_INVALID_PARAMETER;
}
if (!(new = strdupW( name )))
if (!(new = wcsdup( name )))
{
LeaveCriticalSection( &path->cs );
return WBEM_E_OUT_OF_MEMORY;
}
size = (path->num_namespaces + 1) * sizeof(WCHAR *);
if (path->namespaces) tmp = heap_realloc( path->namespaces, size );
else tmp = heap_alloc( size );
if (path->namespaces) tmp = realloc( path->namespaces, size );
else tmp = malloc( size );
if (!tmp)
{
heap_free( new );
free( new );
LeaveCriticalSection( &path->cs );
return WBEM_E_OUT_OF_MEMORY;
}
path->namespaces = tmp;
size = (path->num_namespaces + 1) * sizeof(int);
if (path->len_namespaces) tmp_len = heap_realloc( path->len_namespaces, size );
else tmp_len = heap_alloc( size );
if (path->len_namespaces) tmp_len = realloc( path->len_namespaces, size );
else tmp_len = malloc( size );
if (!tmp_len)
{
heap_free( new );
free( new );
LeaveCriticalSection( &path->cs );
return WBEM_E_OUT_OF_MEMORY;
}
@ -1021,7 +1021,7 @@ static HRESULT WINAPI path_RemoveNamespaceAt(
LeaveCriticalSection( &path->cs );
return WBEM_E_INVALID_PARAMETER;
}
heap_free( path->namespaces[idx] );
free( path->namespaces[idx] );
while (idx < path->num_namespaces - 1)
{
path->namespaces[idx] = path->namespaces[idx + 1];
@ -1044,11 +1044,11 @@ static HRESULT WINAPI path_RemoveAllNamespaces(
EnterCriticalSection( &path->cs );
for (i = 0; i < path->num_namespaces; i++) heap_free( path->namespaces[i] );
for (i = 0; i < path->num_namespaces; i++) free( path->namespaces[i] );
path->num_namespaces = 0;
heap_free( path->namespaces );
free( path->namespaces );
path->namespaces = NULL;
heap_free( path->len_namespaces );
free( path->len_namespaces );
path->len_namespaces = NULL;
LeaveCriticalSection( &path->cs );
@ -1127,11 +1127,11 @@ static HRESULT WINAPI path_SetClassName(
TRACE("%p, %s\n", iface, debugstr_w(name));
if (!name) return WBEM_E_INVALID_PARAMETER;
if (!(class = strdupW( name ))) return WBEM_E_OUT_OF_MEMORY;
if (!(class = wcsdup( name ))) return WBEM_E_OUT_OF_MEMORY;
EnterCriticalSection( &path->cs );
heap_free( path->class );
free( path->class );
path->class = class;
path->len_class = lstrlenW( path->class );
path->flags |= WBEMPATH_INFO_V2_COMPLIANT | WBEMPATH_INFO_CIM_COMPLIANT;
@ -1278,7 +1278,7 @@ HRESULT WbemPath_create( LPVOID *ppObj )
TRACE("%p\n", ppObj);
if (!(path = heap_alloc( sizeof(*path) ))) return E_OUTOFMEMORY;
if (!(path = calloc( 1, sizeof(*path) ))) return E_OUTOFMEMORY;
path->IWbemPath_iface.lpVtbl = &path_vtbl;
path->refs = 1;

View File

@ -57,7 +57,7 @@ static ULONG WINAPI status_code_Release(
if (!refs)
{
TRACE("destroying %p\n", status_code);
heap_free( status_code );
free( status_code );
}
return refs;
}
@ -132,7 +132,7 @@ HRESULT WbemStatusCodeText_create( LPVOID *ppObj )
TRACE("(%p)\n", ppObj);
if (!(sc = heap_alloc( sizeof(*sc) ))) return E_OUTOFMEMORY;
if (!(sc = calloc( 1, sizeof(*sc) ))) return E_OUTOFMEMORY;
sc->IWbemStatusCodeText_iface.lpVtbl = &status_code_vtbl;
sc->refs = 1;

View File

@ -16,15 +16,5 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "wine/heap.h"
HRESULT WbemPath_create(LPVOID *) DECLSPEC_HIDDEN;
HRESULT WbemStatusCodeText_create(LPVOID *) DECLSPEC_HIDDEN;
static inline WCHAR *strdupW( const WCHAR *src )
{
WCHAR *dst;
if (!src) return NULL;
if ((dst = heap_alloc( (lstrlenW( src ) + 1) * sizeof(WCHAR) ))) lstrcpyW( dst, src );
return dst;
}