d3dxof: Fix object leak in error path by calling Release method which does all the work and simplify some inits for better readability.

This commit is contained in:
Christian Costa 2012-01-23 21:37:32 +01:00 committed by Alexandre Julliard
parent 6d3e784d57
commit 096e306300
1 changed files with 24 additions and 29 deletions

View File

@ -940,7 +940,6 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface); IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface);
IDirectXFileDataImpl* object; IDirectXFileDataImpl* object;
HRESULT hr; HRESULT hr;
LPBYTE pstrings = NULL;
TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj); TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
@ -963,34 +962,37 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
object->pobj = HeapAlloc(GetProcessHeap(), 0, sizeof(xobject)*MAX_SUBOBJECTS);
if (!object->pobj)
{
ERR("Out of memory\n");
hr = DXFILEERR_BADALLOC;
goto error;
}
object->pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
if (!object->pstrings)
{
ERR("Out of memory\n");
hr = DXFILEERR_BADALLOC;
goto error;
}
object->cur_enum_object = 0;
object->level = 0;
object->from_ref = FALSE;
This->buf.pxo_globals = This->xobjects; This->buf.pxo_globals = This->xobjects;
This->buf.nb_pxo_globals = This->nb_xobjects; This->buf.nb_pxo_globals = This->nb_xobjects;
This->buf.level = 0; This->buf.level = 0;
This->buf.pdata = NULL; This->buf.pdata = NULL;
This->buf.capacity = 0; This->buf.capacity = 0;
This->buf.cur_pos_data = 0; This->buf.cur_pos_data = 0;
This->buf.cur_pstrings = This->buf.pstrings = object->pstrings;
This->buf.pxo_tab = HeapAlloc(GetProcessHeap(), 0, sizeof(xobject)*MAX_SUBOBJECTS); This->buf.pxo = This->xobjects[This->nb_xobjects] = This->buf.pxo_tab = object->pobj;
if (!This->buf.pxo_tab)
{
ERR("Out of memory\n");
hr = DXFILEERR_BADALLOC;
goto error;
}
This->buf.pxo = This->xobjects[This->nb_xobjects] = This->buf.pxo_tab;
This->buf.pxo->pdata = NULL; This->buf.pxo->pdata = NULL;
This->buf.pxo->nb_subobjects = 1; This->buf.pxo->nb_subobjects = 1;
pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
if (!pstrings)
{
ERR("Out of memory\n");
hr = DXFILEERR_BADALLOC;
goto error;
}
This->buf.cur_pstrings = This->buf.pstrings = object->pstrings = pstrings;
if (!parse_object(&This->buf)) if (!parse_object(&This->buf))
{ {
WARN("Object is not correct\n"); WARN("Object is not correct\n");
@ -998,12 +1000,6 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
goto error; goto error;
} }
object->pstrings = pstrings;
object->pobj = This->buf.pxo;
object->cur_enum_object = 0;
object->level = 0;
object->from_ref = FALSE;
*ppDataObj = (LPDIRECTXFILEDATA)object; *ppDataObj = (LPDIRECTXFILEDATA)object;
/* Get a reference to created object */ /* Get a reference to created object */
@ -1016,9 +1012,8 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
error: error:
HeapFree(GetProcessHeap(), 0, This->buf.pxo_tab); IDirectXFileData_Release(&object->IDirectXFileData_iface);
HeapFree(GetProcessHeap(), 0, This->buf.pdata); *ppDataObj = NULL;
HeapFree(GetProcessHeap(), 0, pstrings);
return hr; return hr;
} }