wined3d: Don't leak memory on failure in allocate_shader_constants().
authorHenri Verbeet <hverbeet@codeweavers.com>
Fri, 12 Dec 2008 08:33:52 +0000 (09:33 +0100)
committerAlexandre Julliard <julliard@winehq.org>
Fri, 12 Dec 2008 10:40:44 +0000 (11:40 +0100)
dlls/wined3d/stateblock.c

index 1f35e82ba256dfe12a53e00c60cc1d540b6c8a25..d568de631ee221a211647dcd01b42e5143031098 100644 (file)
@@ -38,28 +38,39 @@ HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) {
     
     IWineD3DStateBlockImpl *This = object;
 
-#define WINED3D_MEMCHECK(_object) if (NULL == _object) { FIXME("Out of memory!\n"); return E_OUTOFMEMORY; }
-
     /* Allocate space for floating point constants */
     object->pixelShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(pshader_constantsF) * 4);
-    WINED3D_MEMCHECK(object->pixelShaderConstantF);
+    if (!object->pixelShaderConstantF) goto fail;
+
     object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(pshader_constantsF));
-    WINED3D_MEMCHECK(object->changed.pixelShaderConstantsF);
+    if (!object->changed.pixelShaderConstantsF) goto fail;
+
     object->vertexShaderConstantF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
-    WINED3D_MEMCHECK(object->vertexShaderConstantF);
+    if (!object->vertexShaderConstantF) goto fail;
+
     object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOL) * GL_LIMITS(vshader_constantsF));
-    WINED3D_MEMCHECK(object->changed.vertexShaderConstantsF);
+    if (!object->changed.vertexShaderConstantsF) goto fail;
+
     object->contained_vs_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(vshader_constantsF));
-    WINED3D_MEMCHECK(object->contained_vs_consts_f);
+    if (!object->contained_vs_consts_f) goto fail;
+
     object->contained_ps_consts_f = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * GL_LIMITS(pshader_constantsF));
-    WINED3D_MEMCHECK(object->contained_ps_consts_f);
+    if (!object->contained_ps_consts_f) goto fail;
 
     list_init(&object->set_vconstantsF);
     list_init(&object->set_pconstantsF);
 
-#undef WINED3D_MEMCHECK
-
     return WINED3D_OK;
+
+fail:
+    ERR("Failed to allocate memory\n");
+    HeapFree(GetProcessHeap(), 0, object->pixelShaderConstantF);
+    HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF);
+    HeapFree(GetProcessHeap(), 0, object->vertexShaderConstantF);
+    HeapFree(GetProcessHeap(), 0, object->changed.vertexShaderConstantsF);
+    HeapFree(GetProcessHeap(), 0, object->contained_vs_consts_f);
+    HeapFree(GetProcessHeap(), 0, object->contained_ps_consts_f);
+    return E_OUTOFMEMORY;
 }
 
 /** Copy all members of one stateblock to another */