[PATCH 5/5] d3dx9: Correctly handle out of memory conditions while reallocating children array.

Matteo Bruni mbruni at codeweavers.com
Tue Aug 26 09:13:09 CDT 2014


---
 dlls/d3dx9_36/xfile.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/dlls/d3dx9_36/xfile.c b/dlls/d3dx9_36/xfile.c
index f5f3bae..34602c9 100644
--- a/dlls/d3dx9_36/xfile.c
+++ b/dlls/d3dx9_36/xfile.c
@@ -338,15 +338,20 @@ static HRESULT d3dx9_file_data_create(IDirectXFileObject *dxfile_object, ID3DXFi
 
     while (SUCCEEDED(ret = IDirectXFileData_GetNextObject(object->dxfile_data, &data_object)))
     {
+        ID3DXFileData **new_children;
+
         if (object->children)
-            object->children = HeapReAlloc(GetProcessHeap(), 0, object->children, sizeof(ID3DXFileData*) * (object->nb_children + 1));
+            new_children = HeapReAlloc(GetProcessHeap(), 0, object->children,
+                    sizeof(*object->children) * (object->nb_children + 1));
         else
-            object->children = HeapAlloc(GetProcessHeap(), 0, sizeof(ID3DXFileData*));
-        if (!object->children)
+            new_children = HeapAlloc(GetProcessHeap(), 0, sizeof(*object->children));
+        if (!new_children)
         {
             ret = E_OUTOFMEMORY;
             break;
         }
+        object->children = new_children;
+
         ret = d3dx9_file_data_create(data_object, &object->children[object->nb_children]);
         IUnknown_Release(data_object);
         if (FAILED(ret))
@@ -594,15 +599,20 @@ static HRESULT WINAPI d3dx9_file_CreateEnumObject(ID3DXFile *iface, const void *
     /* Fill enum object with top level data objects */
     while (SUCCEEDED(ret = IDirectXFileEnumObject_GetNextDataObject(dxfile_enum_object, &data_object)))
     {
+        ID3DXFileData **new_children;
+
         if (object->children)
-            object->children = HeapReAlloc(GetProcessHeap(), 0, object->children, sizeof(*object->children) * (object->nb_children + 1));
+            new_children = HeapReAlloc(GetProcessHeap(), 0, object->children,
+                    sizeof(*object->children) * (object->nb_children + 1));
         else
-            object->children = HeapAlloc(GetProcessHeap(), 0, sizeof(*object->children));
-        if (!object->children)
+            new_children = HeapAlloc(GetProcessHeap(), 0, sizeof(*object->children));
+        if (!new_children)
         {
             ret = E_OUTOFMEMORY;
             break;
         }
+        object->children = new_children;
+
         ret = d3dx9_file_data_create((IDirectXFileObject*)data_object,
                 &object->children[object->nb_children]);
         IUnknown_Release(data_object);
-- 
1.8.5.5




More information about the wine-patches mailing list