Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/d3dx9_36/surface.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index cf632a4c23..68c14e88e0 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -2232,12 +2232,14 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE if (src_surface_desc.Format == d3d_pixel_format) /* Simple copy */ { hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY); - if (SUCCEEDED(hr)) + if (FAILED(hr)) { - IWICBitmapFrameEncode_WritePixels(frame, height, - locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits); - IDirect3DSurface9_UnlockRect(src_surface); + hr = D3DERR_INVALIDCALL; + goto cleanup; } + IWICBitmapFrameEncode_WritePixels(frame, height, + locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits); + IDirect3DSurface9_UnlockRect(src_surface); } else /* Pixel format conversion */ { @@ -2269,12 +2271,15 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE }
hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY); - if (SUCCEEDED(hr)) + if (FAILED(hr)) { - convert_argb_pixels(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc, - dst_data, dst_pitch, 0, &size, dst_format_desc, 0, NULL); - IDirect3DSurface9_UnlockRect(src_surface); + HeapFree(GetProcessHeap(), 0, dst_data); + hr = D3DERR_INVALIDCALL; + goto cleanup; } + convert_argb_pixels(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc, + dst_data, dst_pitch, 0, &size, dst_format_desc, 0, NULL); + IDirect3DSurface9_UnlockRect(src_surface);
IWICBitmapFrameEncode_WritePixels(frame, height, dst_pitch, dst_pitch * height, dst_data); HeapFree(GetProcessHeap(), 0, dst_data);