For React Native.
From: Zhiyi Zhang zzhang@codeweavers.com
"4b1e53ce wintypes: Make a copy of the passed string in IPropertyValueStatics::CreateString." creates a copy. We should release the string in property_value_Release(). --- dlls/wintypes/main.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/dlls/wintypes/main.c b/dlls/wintypes/main.c index 02121194956..d5e74dc14b3 100644 --- a/dlls/wintypes/main.c +++ b/dlls/wintypes/main.c @@ -598,7 +598,11 @@ static ULONG STDMETHODCALLTYPE property_value_Release(IPropertyValue *iface) if (!refcount) { if (impl->value) + { + if (impl->type == PropertyType_String) + WindowsDeleteString(*(HSTRING *)impl->value); free(impl->value); + } free(impl); }
From: Zhiyi Zhang zzhang@codeweavers.com
Fix a regression from 4b1e53ce. --- dlls/wintypes/main.c | 3 +++ dlls/wintypes/tests/wintypes.c | 3 +++ 2 files changed, 6 insertions(+)
diff --git a/dlls/wintypes/main.c b/dlls/wintypes/main.c index d5e74dc14b3..14ee3bac417 100644 --- a/dlls/wintypes/main.c +++ b/dlls/wintypes/main.c @@ -1466,6 +1466,9 @@ static HRESULT STDMETHODCALLTYPE property_value_statics_CreateString(IPropertyVa
TRACE("iface %p, value %s, property_value %p.\n", iface, debugstr_hstring(value_str), property_value);
+ if (!property_value) + return E_POINTER; + if (FAILED(hr = WindowsDuplicateString(value_str, &value))) { *property_value = NULL; diff --git a/dlls/wintypes/tests/wintypes.c b/dlls/wintypes/tests/wintypes.c index 3025ab69235..a7af1ebbd88 100644 --- a/dlls/wintypes/tests/wintypes.c +++ b/dlls/wintypes/tests/wintypes.c @@ -834,6 +834,9 @@ static void test_IPropertyValueStatics(void) hr = IPropertyValue_GetBoolean(value, &ret); ok(hr == TYPE_E_TYPEMISMATCH, "Got unexpected hr %#lx.\n", hr);
+ hr = IPropertyValueStatics_CreateString(statics, (HSTRING)-1, NULL); + ok(hr == E_POINTER, "Got unexpected hr %#lx.\n", hr); + IPropertyValue_Release(value);
/* Parameter checks for array types */
From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/wintypes/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/dlls/wintypes/main.c b/dlls/wintypes/main.c index 14ee3bac417..2cd7879e12a 100644 --- a/dlls/wintypes/main.c +++ b/dlls/wintypes/main.c @@ -716,8 +716,14 @@ static HRESULT STDMETHODCALLTYPE property_value_GetBoolean(IPropertyValue *iface
static HRESULT STDMETHODCALLTYPE property_value_GetString(IPropertyValue *iface, HSTRING *value) { + HRESULT hr; + TRACE("iface %p, value %p.\n", iface, value); - return property_value_get_primitive(PropertyType_String); + + hr = property_value_get_primitive(PropertyType_String); + if (SUCCEEDED(hr)) + WindowsDuplicateString(*value, value); + return hr; }
static HRESULT STDMETHODCALLTYPE property_value_GetGuid(IPropertyValue *iface, GUID *value)
From: Zhiyi Zhang zzhang@codeweavers.com
Similar to 4b1e53ce to avoid use-after-free. --- dlls/wintypes/main.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/dlls/wintypes/main.c b/dlls/wintypes/main.c index 2cd7879e12a..08021564315 100644 --- a/dlls/wintypes/main.c +++ b/dlls/wintypes/main.c @@ -600,7 +600,17 @@ static ULONG STDMETHODCALLTYPE property_value_Release(IPropertyValue *iface) if (impl->value) { if (impl->type == PropertyType_String) + { WindowsDeleteString(*(HSTRING *)impl->value); + } + else if (impl->type == PropertyType_StringArray) + { + HSTRING *string_array = impl->value; + unsigned int i; + + for (i = 0; i < impl->value_size; i++) + WindowsDeleteString(string_array[i]); + } free(impl->value); } free(impl); @@ -1614,8 +1624,38 @@ static HRESULT STDMETHODCALLTYPE property_value_statics_CreateBooleanArray(IProp static HRESULT STDMETHODCALLTYPE property_value_statics_CreateStringArray(IPropertyValueStatics *iface, UINT32 value_size, HSTRING *value, IInspectable **property_value) { + struct property_value *impl; + HSTRING *new_value; + unsigned int i; + TRACE("iface %p, value_size %u, value %p, property_value %p.\n", iface, value_size, value, property_value); - return create_primitive_property_value_array(PropertyType_StringArray); + + if (!value || !property_value) + return E_POINTER; + + impl = calloc(1, sizeof(*impl)); + if (!impl) + return E_OUTOFMEMORY; + + new_value = calloc(value_size, sizeof(HSTRING)); + if (!new_value) + { + free(impl); + return E_OUTOFMEMORY; + } + + for (i = 0; i < value_size; i++) + WindowsDuplicateString(value[i], &new_value[i]); + + impl->IPropertyValue_iface.lpVtbl = &property_value_vtbl; + impl->type = PropertyType_StringArray; + impl->ref = 1; + impl->value = new_value; + impl->value_size = value_size; + + *property_value = (IInspectable *)&impl->IPropertyValue_iface; + return S_OK; + }
static HRESULT STDMETHODCALLTYPE property_value_statics_CreateInspectableArray(IPropertyValueStatics *iface,
From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/wintypes/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/dlls/wintypes/main.c b/dlls/wintypes/main.c index 08021564315..287e5992225 100644 --- a/dlls/wintypes/main.c +++ b/dlls/wintypes/main.c @@ -841,8 +841,18 @@ static HRESULT STDMETHODCALLTYPE property_value_GetBooleanArray(IPropertyValue *
static HRESULT STDMETHODCALLTYPE property_value_GetStringArray(IPropertyValue *iface, UINT32 *value_size, HSTRING **value) { + unsigned int i; + HRESULT hr; + TRACE("iface %p, value_size %p, value %p.\n", iface, value_size, value); - return property_value_get_primitive_array(PropertyType_StringArray); + + hr = property_value_get_primitive_array(PropertyType_StringArray); + if (SUCCEEDED(hr)) + { + for (i = 0; i < *value_size; i++) + WindowsDuplicateString((*value)[i], &(*value)[i]); + } + return hr; }
static HRESULT STDMETHODCALLTYPE property_value_GetInspectableArray(IPropertyValue *iface, UINT32 *value_size, IInspectable ***value)