From b0f13fef660a46a781b1dd849996049ebe514242 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 28 Aug 2015 01:13:32 +0200
Subject: wined3d: Alloc the buffer map array before mapping the buffer.

FIXME: This needs to go into whatever patch creates the VBO on first map.
---
 dlls/wined3d/buffer.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 0c3dc56..531eb39 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -1317,27 +1317,28 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device
         buffer->flags |= WINED3D_BUFFER_CREATEBO;
     }
 
+    buffer->maps = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->maps));
+    if (!buffer->maps)
+    {
+        ERR("Out of memory\n");
+        buffer_unload(&buffer->resource);
+        resource_cleanup(&buffer->resource);
+        return E_OUTOFMEMORY;
+    }
+    buffer->maps_size = 1;
+
     if (data)
     {
         if (FAILED(hr = wined3d_buffer_upload_data(buffer, NULL, data->data)))
         {
             ERR("Failed to upload data, hr %#x.\n", hr);
+            HeapFree(GetProcessHeap(), 0, buffer->maps);
             buffer_unload(&buffer->resource);
             resource_cleanup(&buffer->resource);
             return hr;
         }
     }
 
-    buffer->maps = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->maps));
-    if (!buffer->maps)
-    {
-        ERR("Out of memory\n");
-        buffer_unload(&buffer->resource);
-        resource_cleanup(&buffer->resource);
-        return E_OUTOFMEMORY;
-    }
-    buffer->maps_size = 1;
-
     if (wined3d_settings.cs_multithreaded)
         buffer->flags |= WINED3D_BUFFER_DOUBLEBUFFER;
 
-- 
2.6.4

