Giovanni Mascellani : mfplat: Do not allocate more memory than requested.

Alexandre Julliard julliard at winehq.org
Thu Mar 17 17:18:31 CDT 2022


Module: wine
Branch: master
Commit: 52b5caa48884d4798e02d7cedba596da6a757aec
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=52b5caa48884d4798e02d7cedba596da6a757aec

Author: Giovanni Mascellani <gmascellani at codeweavers.com>
Date:   Tue Mar 15 14:29:22 2022 +0100

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 at codeweavers.com>
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mfplat/buffer.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c
index 18c77c87ec2..8ea2283e24b 100644
--- a/dlls/mfplat/buffer.c
+++ b/dlls/mfplat/buffer.c
@@ -1262,8 +1262,6 @@ static const IMFDXGIBufferVtbl dxgi_buffer_vtbl =
 static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD alignment,
         const IMFMediaBufferVtbl *vtbl)
 {
-    size_t size;
-
     if (alignment < MF_16_BYTE_ALIGNMENT)
         alignment = MF_16_BYTE_ALIGNMENT;
     alignment++;
@@ -1279,10 +1277,9 @@ static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD
         alignment++;
     }
 
-    size = ALIGN_SIZE(max_length, alignment - 1);
-    if (!(buffer->data = _aligned_malloc(size, alignment)))
+    if (!(buffer->data = _aligned_malloc(max_length, alignment)))
         return E_OUTOFMEMORY;
-    memset(buffer->data, 0, size);
+    memset(buffer->data, 0, max_length);
 
     buffer->IMFMediaBuffer_iface.lpVtbl = vtbl;
     buffer->refcount = 1;




More information about the wine-cvs mailing list