wbemprox: Fix BSTR leaks caused by incorrect use of SafeArrayPutElement() (Valgrind).

This commit is contained in:
Nikolay Sivov 2015-04-22 13:13:55 +03:00 committed by Alexandre Julliard
parent f068eb9acd
commit 84a8ae79d2
2 changed files with 14 additions and 1 deletions

View File

@ -700,6 +700,7 @@ SAFEARRAY *to_safearray( const struct array *array, CIMTYPE type )
SafeArrayDestroy( ret );
return NULL;
}
SysFreeString( str );
}
else if (SafeArrayPutElement( ret, &i, ptr ) != S_OK)
{
@ -1002,6 +1003,7 @@ HRESULT get_properties( const struct view *view, LONG flags, SAFEARRAY **props )
SafeArrayDestroy( sa );
return E_OUTOFMEMORY;
}
SysFreeString( str );
j++;
}
*props = sa;

View File

@ -51,6 +51,12 @@ static HRESULT to_bstr_array( BSTR *strings, DWORD count, VARIANT *var )
return S_OK;
}
static void free_bstr_array( BSTR *strings, DWORD count )
{
while (count--)
SysFreeString( *(strings++) );
}
static HRESULT to_i4_array( DWORD *values, DWORD count, VARIANT *var )
{
SAFEARRAY *sa;
@ -114,7 +120,11 @@ static HRESULT enum_key( HKEY root, const WCHAR *subkey, VARIANT *names, VARIANT
}
i++;
}
if (hr == S_OK && !res) hr = to_bstr_array( strings, i, names );
if (hr == S_OK && !res)
{
hr = to_bstr_array( strings, i, names );
free_bstr_array( strings, i );
}
set_variant( VT_UI4, res, NULL, retval );
RegCloseKey( hkey );
heap_free( strings );
@ -218,6 +228,7 @@ static HRESULT enum_values( HKEY root, const WCHAR *subkey, VARIANT *names, VARI
if (hr == S_OK && !res)
{
hr = to_bstr_array( value_names, i, names );
free_bstr_array( value_names, i );
if (hr == S_OK) hr = to_i4_array( value_types, i, types );
}