Hi,
Il 08/03/22 14:06, Nikolay Sivov ha scritto:
@@ -1254,8 +1256,26 @@ static const IMFDXGIBufferVtbl dxgi_buffer_vtbl = static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD alignment, const IMFMediaBufferVtbl *vtbl) {
- if (!(buffer->data = calloc(1, ALIGN_SIZE(max_length, alignment))))
- size_t size;
- if (!alignment) alignment = MF_64_BYTE_ALIGNMENT;
BTW, I am not seeing this behavior: on Windows 10 I always see an alignment of at least 16 bytes, but specifying no alignment certainly doesn't result in a 64 bytes alignment. See for example[1], which gives, for each alignment, the bitwise OR of 20 different attempts at allocating with that alignment. You can see that for alignment set to zero you get an alignment that is worse than 64 bytes.
[1] https://testbot.winehq.org/JobDetails.pl?Key=110459&f101=exe64.report#k1...
Now, giving an excessive alignment is probably not going to be a problem, but I'd remove that line anyway.
- alignment++;
- if (alignment & (alignment - 1))
- {
alignment--;
alignment |= alignment >> 1;
alignment |= alignment >> 2;
alignment |= alignment >> 4;
alignment |= alignment >> 8;
alignment |= alignment >> 16;
alignment++;
- }
- size = ALIGN_SIZE(max_length, alignment - 1);
Why this? You're potentially allocating much more memory than the user requested. How did you test this happens on Windows?
if (!(buffer->data = _aligned_malloc(size, alignment))) return E_OUTOFMEMORY;
memset(buffer->data, 0, size);
buffer->IMFMediaBuffer_iface.lpVtbl = vtbl; buffer->refcount = 1;
Thanks, Giovanni.