[PATCH 3/5] d3dx9_36: Improve error handling in remap_faces_for_attrsort.

Stefan Dösinger stefan at codeweavers.com
Fri Jan 3 07:17:18 CST 2014


This patch looks like it fixes a memory leak, but there was none to begin
with because the caller frees *face_remap in case of an error. I think
this was bad style though.
---
 dlls/d3dx9_36/mesh.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx9_36/mesh.c b/dlls/d3dx9_36/mesh.c
index 133f14d..b713079 100644
--- a/dlls/d3dx9_36/mesh.c
+++ b/dlls/d3dx9_36/mesh.c
@@ -1615,12 +1615,17 @@ static HRESULT remap_faces_for_attrsort(struct d3dx9_mesh *This, const DWORD *in
     DWORD **sorted_attrib_ptr_buffer = NULL;
     DWORD i;
 
-    *face_remap = HeapAlloc(GetProcessHeap(), 0, This->numfaces * sizeof(**face_remap));
     sorted_attrib_ptr_buffer = HeapAlloc(GetProcessHeap(), 0, This->numfaces * sizeof(*sorted_attrib_ptr_buffer));
-    if (!*face_remap || !sorted_attrib_ptr_buffer) {
+    if (!sorted_attrib_ptr_buffer)
+        return E_OUTOFMEMORY;
+
+    *face_remap = HeapAlloc(GetProcessHeap(), 0, This->numfaces * sizeof(**face_remap));
+    if (!*face_remap)
+    {
         HeapFree(GetProcessHeap(), 0, sorted_attrib_ptr_buffer);
         return E_OUTOFMEMORY;
     }
+
     for (i = 0; i < This->numfaces; i++)
         sorted_attrib_ptr_buffer[i] = &attrib_buffer[i];
     qsort(sorted_attrib_ptr_buffer, This->numfaces, sizeof(*sorted_attrib_ptr_buffer),
-- 
1.8.3.4 (Apple Git-47)




More information about the wine-patches mailing list