wbemprox: Always convert from BSTR.

This commit is contained in:
Hans Leidekker 2012-10-12 14:25:13 +02:00 committed by Alexandre Julliard
parent dca427fded
commit 3b8266d20b
3 changed files with 40 additions and 14 deletions

View File

@ -232,6 +232,20 @@ static struct record *create_record( const struct column *columns, UINT num_cols
return record;
}
void destroy_array( struct array *array, CIMTYPE type )
{
UINT i, size;
if (!array) return;
if (type == CIM_STRING || type == CIM_DATETIME)
{
size = get_type_size( type );
for (i = 0; i < array->count; i++) heap_free( *(WCHAR **)((char *)array->ptr + i * size) );
}
heap_free( array->ptr );
heap_free( array );
}
static void destroy_record( struct record *record )
{
UINT i;
@ -241,11 +255,8 @@ static void destroy_record( struct record *record )
{
if (record->fields[i].type == CIM_STRING || record->fields[i].type == CIM_DATETIME)
heap_free( record->fields[i].u.sval );
else if ((record->fields[i].type & CIM_FLAG_ARRAY) && record->fields[i].u.aval)
{
heap_free( record->fields[i].u.aval->ptr );
heap_free( record->fields[i].u.aval );
}
else if (record->fields[i].type & CIM_FLAG_ARRAY)
destroy_array( record->fields[i].u.aval, record->fields[i].type & CIM_TYPE_MASK );
}
heap_free( record->fields );
heap_free( record );

View File

@ -639,8 +639,6 @@ static void set_variant( VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret
V_VT( ret ) = type;
}
#define CIM_TYPE_MASK 0xfff
HRESULT get_propval( const struct view *view, UINT index, const WCHAR *name, VARIANT *ret,
CIMTYPE *type, LONG *flavor )
{
@ -750,19 +748,33 @@ static struct array *to_array( VARIANT *var, CIMTYPE *type )
ret->count = bound + 1;
size = get_type_size( basetype );
if (!(ret->ptr = heap_alloc( ret->count * size )))
if (!(ret->ptr = heap_alloc_zero( ret->count * size )))
{
heap_free( ret );
return NULL;
}
for (i = 0; i < ret->count; i++)
{
if (SafeArrayGetElement( V_ARRAY( var ), &i, (char *)ret->ptr + i * size ) != S_OK)
void *ptr = (char *)ret->ptr + i * size;
if (vartype == VT_BSTR)
{
if (vartype == VT_BSTR)
for (i--; i >= 0; i--) SysFreeString( *(BSTR *)(char *)ret->ptr + i * size );
heap_free( ret->ptr );
heap_free( ret );
BSTR str;
if (SafeArrayGetElement( V_ARRAY( var ), &i, &str ) != S_OK)
{
destroy_array( ret, basetype );
return NULL;
}
*(WCHAR **)ptr = heap_strdupW( str );
SysFreeString( str );
if (!*(WCHAR **)ptr)
{
destroy_array( ret, basetype );
return NULL;
}
}
else if (SafeArrayGetElement( V_ARRAY( var ), &i, ptr ) != S_OK)
{
destroy_array( ret, basetype );
return NULL;
}
}
@ -790,7 +802,7 @@ HRESULT to_longlong( VARIANT *var, LONGLONG *val, CIMTYPE *type )
*type = CIM_BOOLEAN;
break;
case VT_BSTR:
*val = (INT_PTR)SysAllocString( V_BSTR( var ) );
*val = (INT_PTR)heap_strdupW( V_BSTR( var ) );
if (!*val) return E_OUTOFMEMORY;
*type = CIM_STRING;
break;

View File

@ -31,6 +31,8 @@ enum param_direction
PARAM_IN = 1
};
#define CIM_TYPE_MASK 0x00000fff
#define COL_TYPE_MASK 0x0000ffff
#define COL_FLAG_DYNAMIC 0x00010000
#define COL_FLAG_KEY 0x00020000
@ -177,6 +179,7 @@ HRESULT get_propval( const struct view *, UINT, const WCHAR *, VARIANT *,
HRESULT put_propval( const struct view *, UINT, const WCHAR *, VARIANT *, CIMTYPE ) DECLSPEC_HIDDEN;
HRESULT to_longlong( VARIANT *, LONGLONG *, CIMTYPE * ) DECLSPEC_HIDDEN;
SAFEARRAY *to_safearray( const struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
void destroy_array( struct array *, CIMTYPE ) DECLSPEC_HIDDEN;
HRESULT get_properties( const struct view *, SAFEARRAY ** ) DECLSPEC_HIDDEN;
HRESULT get_object( const WCHAR *, IWbemClassObject ** ) DECLSPEC_HIDDEN;
BSTR get_method_name( const WCHAR *, UINT ) DECLSPEC_HIDDEN;