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

Alexandre Julliard julliard at wine.codeweavers.com
Wed Apr 22 10:26:41 CDT 2015


Module: wine
Branch: master
Commit: 84a8ae79d289e403456a740f701d0ebe90ae88d0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=84a8ae79d289e403456a740f701d0ebe90ae88d0

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed Apr 22 13:13:55 2015 +0300

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

---

 dlls/wbemprox/query.c |  2 ++
 dlls/wbemprox/reg.c   | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/dlls/wbemprox/query.c b/dlls/wbemprox/query.c
index 7ae9a0f..6f66603 100644
--- a/dlls/wbemprox/query.c
+++ b/dlls/wbemprox/query.c
@@ -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;
diff --git a/dlls/wbemprox/reg.c b/dlls/wbemprox/reg.c
index 4bf249b..7544c3c 100644
--- a/dlls/wbemprox/reg.c
+++ b/dlls/wbemprox/reg.c
@@ -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 );
     }
 




More information about the wine-cvs mailing list