Commit a8c319ca authored by Jason Millard's avatar Jason Millard Committed by Alexandre Julliard

vbscript: Fix memory leak in owned safearray iterator.

parent afb2125c
......@@ -1487,7 +1487,7 @@ static HRESULT interp_newenum(exec_ctx_t *ctx)
case VT_VARIANT|VT_ARRAY|VT_BYREF: {
IEnumVARIANT *iter;
hres = create_safearray_iter(V_ISBYREF(v.v) ? *V_ARRAYREF(v.v) : V_ARRAY(v.v), &iter);
hres = create_safearray_iter(V_ISBYREF(v.v) ? *V_ARRAYREF(v.v) : V_ARRAY(v.v), v.owned && !V_ISBYREF(v.v), &iter);
if(FAILED(hres))
return hres;
......
......@@ -28,6 +28,7 @@ typedef struct {
LONG ref;
SAFEARRAY *sa;
BOOL owned;
ULONG i, size;
} safearray_iter;
......@@ -75,8 +76,11 @@ static ULONG WINAPI safearray_iter_IEnumVARIANT_Release(IEnumVARIANT *iface)
TRACE("(%p) ref=%ld\n", iface, ref);
if(!ref) {
if(This->sa)
if(This->sa) {
SafeArrayUnlock(This->sa);
if(This->owned)
SafeArrayDestroy(This->sa);
}
free(This);
}
......@@ -160,7 +164,7 @@ static ULONG get_safearray_size(SAFEARRAY *sa)
return ret;
}
HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev)
HRESULT create_safearray_iter(SAFEARRAY *sa, BOOL owned, IEnumVARIANT **ev)
{
safearray_iter *iter;
HRESULT hres;
......@@ -185,6 +189,7 @@ HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev)
iter->IEnumVARIANT_iface.lpVtbl = &safearray_iter_EnumVARIANTVtbl;
iter->ref = 1;
iter->sa = sa;
iter->owned = owned;
iter->i = 0;
iter->size = get_safearray_size(sa);
......
......@@ -415,7 +415,7 @@ BSTR string_replace(BSTR,BSTR,BSTR,int,int,int) DECLSPEC_HIDDEN;
void map_vbs_exception(EXCEPINFO *) DECLSPEC_HIDDEN;
HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev) DECLSPEC_HIDDEN;
HRESULT create_safearray_iter(SAFEARRAY *sa, BOOL owned, IEnumVARIANT **ev) DECLSPEC_HIDDEN;
#define FACILITY_VBS 0xa
#define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment