mfplat: Do not allocate more memory than requested.

It is totally fine (though maybe a little strange) to allocate 10 bytes
requesting an alignment to a megabyte boundary or more, and this
shouldn't result in wasting an (nearly) entire megabyte of memory.

Signed-off-by: Giovanni Mascellani <gmascellani@codeweavers.com>
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Giovanni Mascellani 2022-03-15 14:29:22 +01:00 committed by Alexandre Julliard
parent 20c4896b12
commit 52b5caa488
1 changed files with 2 additions and 5 deletions

View File

@ -1262,8 +1262,6 @@ static const IMFDXGIBufferVtbl dxgi_buffer_vtbl =
static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD alignment, static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD alignment,
const IMFMediaBufferVtbl *vtbl) const IMFMediaBufferVtbl *vtbl)
{ {
size_t size;
if (alignment < MF_16_BYTE_ALIGNMENT) if (alignment < MF_16_BYTE_ALIGNMENT)
alignment = MF_16_BYTE_ALIGNMENT; alignment = MF_16_BYTE_ALIGNMENT;
alignment++; alignment++;
@ -1279,10 +1277,9 @@ static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD
alignment++; alignment++;
} }
size = ALIGN_SIZE(max_length, alignment - 1); if (!(buffer->data = _aligned_malloc(max_length, alignment)))
if (!(buffer->data = _aligned_malloc(size, alignment)))
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
memset(buffer->data, 0, size); memset(buffer->data, 0, max_length);
buffer->IMFMediaBuffer_iface.lpVtbl = vtbl; buffer->IMFMediaBuffer_iface.lpVtbl = vtbl;
buffer->refcount = 1; buffer->refcount = 1;