From 096e3063000609fbe8aa9f7a6afd088bc0bee009 Mon Sep 17 00:00:00 2001 From: Christian Costa Date: Mon, 23 Jan 2012 21:37:32 +0100 Subject: [PATCH] d3dxof: Fix object leak in error path by calling Release method which does all the work and simplify some inits for better readability. --- dlls/d3dxof/d3dxof.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/dlls/d3dxof/d3dxof.c b/dlls/d3dxof/d3dxof.c index 3a6ce2055cf..38882a8095b 100644 --- a/dlls/d3dxof/d3dxof.c +++ b/dlls/d3dxof/d3dxof.c @@ -940,7 +940,6 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE IDirectXFileEnumObjectImpl *This = impl_from_IDirectXFileEnumObject(iface); IDirectXFileDataImpl* object; HRESULT hr; - LPBYTE pstrings = NULL; TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj); @@ -963,33 +962,36 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE if (FAILED(hr)) return hr; - This->buf.pxo_globals = This->xobjects; - This->buf.nb_pxo_globals = This->nb_xobjects; - This->buf.level = 0; - This->buf.pdata = NULL; - This->buf.capacity = 0; - This->buf.cur_pos_data = 0; - - This->buf.pxo_tab = HeapAlloc(GetProcessHeap(), 0, sizeof(xobject)*MAX_SUBOBJECTS); - if (!This->buf.pxo_tab) + object->pobj = HeapAlloc(GetProcessHeap(), 0, sizeof(xobject)*MAX_SUBOBJECTS); + if (!object->pobj) { 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->nb_subobjects = 1; - - pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER); - if (!pstrings) + object->pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER); + if (!object->pstrings) { ERR("Out of memory\n"); hr = DXFILEERR_BADALLOC; goto error; } - This->buf.cur_pstrings = This->buf.pstrings = object->pstrings = pstrings; + + object->cur_enum_object = 0; + object->level = 0; + object->from_ref = FALSE; + + This->buf.pxo_globals = This->xobjects; + This->buf.nb_pxo_globals = This->nb_xobjects; + This->buf.level = 0; + This->buf.pdata = NULL; + This->buf.capacity = 0; + This->buf.cur_pos_data = 0; + This->buf.cur_pstrings = This->buf.pstrings = object->pstrings; + This->buf.pxo = This->xobjects[This->nb_xobjects] = This->buf.pxo_tab = object->pobj; + This->buf.pxo->pdata = NULL; + This->buf.pxo->nb_subobjects = 1; if (!parse_object(&This->buf)) { @@ -998,12 +1000,6 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE 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; /* Get a reference to created object */ @@ -1016,9 +1012,8 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE error: - HeapFree(GetProcessHeap(), 0, This->buf.pxo_tab); - HeapFree(GetProcessHeap(), 0, This->buf.pdata); - HeapFree(GetProcessHeap(), 0, pstrings); + IDirectXFileData_Release(&object->IDirectXFileData_iface); + *ppDataObj = NULL; return hr; } -- 2.11.4.GIT