ole32: Store the InterfaceList object in the IEnumMoniker object.

This is because the IEnumMoniker object is supposed to free the memory 
passed to it, but the array of InterfaceData pointers is inside the 
InterfaceList memory block.
This commit is contained in:
Rob Shearman 2007-11-10 16:05:23 +00:00 committed by Alexandre Julliard
parent e8b9a427be
commit 2c1ba188d6
1 changed files with 25 additions and 29 deletions

View File

@ -94,15 +94,14 @@ typedef struct EnumMonikerImpl
const IEnumMonikerVtbl *lpVtbl; const IEnumMonikerVtbl *lpVtbl;
LONG ref; LONG ref;
InterfaceData **monikers; InterfaceList *moniker_list;
ULONG moniker_count;
ULONG pos; ULONG pos;
} EnumMonikerImpl; } EnumMonikerImpl;
/* IEnumMoniker Local functions*/ /* IEnumMoniker Local functions*/
static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(InterfaceData **monikers, static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(InterfaceList *moniker_list,
ULONG moniker_count, ULONG pos, IEnumMoniker **ppenumMoniker); ULONG pos, IEnumMoniker **ppenumMoniker);
static IrotHandle get_irot_handle(void) static IrotHandle get_irot_handle(void)
{ {
@ -934,8 +933,7 @@ RunningObjectTableImpl_EnumRunning(IRunningObjectTable* iface,
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
hr = EnumMonikerImpl_CreateEnumROTMoniker(interface_list->interfaces, hr = EnumMonikerImpl_CreateEnumROTMoniker(interface_list,
interface_list->size,
0, ppenumMoniker); 0, ppenumMoniker);
return hr; return hr;
@ -1320,9 +1318,9 @@ static ULONG WINAPI EnumMonikerImpl_Release(IEnumMoniker* iface)
TRACE("(%p) Deleting\n",This); TRACE("(%p) Deleting\n",This);
for (i = 0; i < This->moniker_count; i++) for (i = 0; i < This->moniker_list->size; i++)
HeapFree(GetProcessHeap(), 0, This->monikers[i]); HeapFree(GetProcessHeap(), 0, This->moniker_list->interfaces[i]);
HeapFree(GetProcessHeap(), 0, This->monikers); HeapFree(GetProcessHeap(), 0, This->moniker_list);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
@ -1337,13 +1335,13 @@ static HRESULT WINAPI EnumMonikerImpl_Next(IEnumMoniker* iface, ULONG celt, IM
EnumMonikerImpl *This = (EnumMonikerImpl *)iface; EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
HRESULT hr = S_OK; HRESULT hr = S_OK;
TRACE("(%p) TabCurrentPos %d Tablastindx %d\n", This, This->pos, This->moniker_count); TRACE("(%p) TabCurrentPos %d Tablastindx %d\n", This, This->pos, This->moniker_list->size);
/* retrieve the requested number of moniker from the current position */ /* retrieve the requested number of moniker from the current position */
for(i = 0; (This->pos < This->moniker_count) && (i < celt); i++) for(i = 0; (This->pos < This->moniker_list->size) && (i < celt); i++)
{ {
IStream *stream; IStream *stream;
hr = create_stream_on_mip_ro(This->monikers[This->pos++], &stream); hr = create_stream_on_mip_ro(This->moniker_list->interfaces[This->pos++], &stream);
if (hr != S_OK) break; if (hr != S_OK) break;
hr = CoUnmarshalInterface(stream, &IID_IMoniker, (void **)&rgelt[i]); hr = CoUnmarshalInterface(stream, &IID_IMoniker, (void **)&rgelt[i]);
IStream_Release(stream); IStream_Release(stream);
@ -1372,7 +1370,7 @@ static HRESULT WINAPI EnumMonikerImpl_Skip(IEnumMoniker* iface, ULONG celt)
TRACE("(%p)\n",This); TRACE("(%p)\n",This);
if (This->pos + celt >= This->moniker_count) if (This->pos + celt >= This->moniker_list->size)
return S_FALSE; return S_FALSE;
This->pos += celt; This->pos += celt;
@ -1400,35 +1398,35 @@ static HRESULT WINAPI EnumMonikerImpl_Reset(IEnumMoniker* iface)
static HRESULT WINAPI EnumMonikerImpl_Clone(IEnumMoniker* iface, IEnumMoniker ** ppenum) static HRESULT WINAPI EnumMonikerImpl_Clone(IEnumMoniker* iface, IEnumMoniker ** ppenum)
{ {
EnumMonikerImpl *This = (EnumMonikerImpl *)iface; EnumMonikerImpl *This = (EnumMonikerImpl *)iface;
InterfaceData **monikers; InterfaceList *moniker_list;
ULONG i; ULONG i;
TRACE("(%p)\n",This); TRACE("(%p)\n",This);
*ppenum = NULL; *ppenum = NULL;
monikers = HeapAlloc(GetProcessHeap(), 0, sizeof(*monikers)*This->moniker_count); moniker_list = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(InterfaceList, interfaces[This->moniker_list->size]));
if (!monikers) if (!moniker_list)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
for (i = 0; i < This->moniker_count; i++) moniker_list->size = This->moniker_list->size;
for (i = 0; i < This->moniker_list->size; i++)
{ {
SIZE_T size = FIELD_OFFSET(InterfaceData, abData[This->monikers[i]->ulCntData]); SIZE_T size = FIELD_OFFSET(InterfaceData, abData[This->moniker_list->interfaces[i]->ulCntData]);
monikers[i] = HeapAlloc(GetProcessHeap(), 0, size); moniker_list->interfaces[i] = HeapAlloc(GetProcessHeap(), 0, size);
if (!monikers[i]) if (!moniker_list->interfaces[i])
{ {
ULONG end = i; ULONG end = i;
for (i = 0; i < end; i++) for (i = 0; i < end; i++)
HeapFree(GetProcessHeap(), 0, monikers[i]); HeapFree(GetProcessHeap(), 0, moniker_list->interfaces[i]);
HeapFree(GetProcessHeap(), 0, monikers); HeapFree(GetProcessHeap(), 0, moniker_list);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
memcpy(monikers[i], This->monikers[i], size); memcpy(moniker_list->interfaces[i], This->moniker_list->interfaces[i], size);
} }
/* copy the enum structure */ /* copy the enum structure */
return EnumMonikerImpl_CreateEnumROTMoniker(monikers, This->moniker_count, return EnumMonikerImpl_CreateEnumROTMoniker(moniker_list, This->pos, ppenum);
This->pos, ppenum);
} }
/* Virtual function table for the IEnumMoniker class. */ /* Virtual function table for the IEnumMoniker class. */
@ -1448,8 +1446,7 @@ static const IEnumMonikerVtbl VT_EnumMonikerImpl =
* Used by EnumRunning to create the structure and EnumClone * Used by EnumRunning to create the structure and EnumClone
* to copy the structure * to copy the structure
*/ */
static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(InterfaceData **monikers, static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(InterfaceList *moniker_list,
ULONG moniker_count,
ULONG current_pos, ULONG current_pos,
IEnumMoniker **ppenumMoniker) IEnumMoniker **ppenumMoniker)
{ {
@ -1469,8 +1466,7 @@ static HRESULT WINAPI EnumMonikerImpl_CreateEnumROTMoniker(InterfaceData **monik
/* the initial reference is set to "1" */ /* the initial reference is set to "1" */
This->ref = 1; /* set the ref count to one */ This->ref = 1; /* set the ref count to one */
This->pos = current_pos; /* Set the list start posn */ This->pos = current_pos; /* Set the list start posn */
This->moniker_count = moniker_count; /* Need the same size table as ROT */ This->moniker_list = moniker_list;
This->monikers = monikers;
*ppenumMoniker = (IEnumMoniker*)This; *ppenumMoniker = (IEnumMoniker*)This;