[PATCH] mfplat: Use CRT allocation functions.

Nikolay Sivov nsivov at codeweavers.com
Wed May 12 08:09:03 CDT 2021


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/mfplat/buffer.c         |  37 +++---
 dlls/mfplat/main.c           | 210 +++++++++++++++--------------------
 dlls/mfplat/mediatype.c      |  37 +++---
 dlls/mfplat/mfplat_private.h |   3 +-
 dlls/mfplat/sample.c         |  28 +++--
 5 files changed, 136 insertions(+), 179 deletions(-)

diff --git a/dlls/mfplat/buffer.c b/dlls/mfplat/buffer.c
index f428630ea01..e04cc1a9251 100644
--- a/dlls/mfplat/buffer.c
+++ b/dlls/mfplat/buffer.c
@@ -141,9 +141,9 @@ static ULONG WINAPI memory_buffer_Release(IMFMediaBuffer *iface)
             clear_attributes_object(&buffer->dxgi_surface.attributes);
         }
         DeleteCriticalSection(&buffer->cs);
-        heap_free(buffer->_2d.linear_buffer);
-        heap_free(buffer->data);
-        heap_free(buffer);
+        free(buffer->_2d.linear_buffer);
+        free(buffer->data);
+        free(buffer);
     }
 
     return refcount;
@@ -278,7 +278,7 @@ static HRESULT WINAPI memory_1d_2d_buffer_Lock(IMFMediaBuffer *iface, BYTE **dat
         hr = MF_E_INVALIDREQUEST;
     else if (!buffer->_2d.linear_buffer)
     {
-        if (!(buffer->_2d.linear_buffer = heap_alloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT))))
+        if (!(buffer->_2d.linear_buffer = malloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT))))
             hr = E_OUTOFMEMORY;
     }
 
@@ -310,7 +310,7 @@ static HRESULT WINAPI memory_1d_2d_buffer_Unlock(IMFMediaBuffer *iface)
         MFCopyImage(buffer->data, buffer->_2d.pitch, buffer->_2d.linear_buffer, buffer->_2d.width,
                 buffer->_2d.width, buffer->_2d.height);
 
-        heap_free(buffer->_2d.linear_buffer);
+        free(buffer->_2d.linear_buffer);
         buffer->_2d.linear_buffer = NULL;
     }
 
@@ -349,7 +349,7 @@ static HRESULT WINAPI d3d9_surface_buffer_Lock(IMFMediaBuffer *iface, BYTE **dat
     {
         D3DLOCKED_RECT rect;
 
-        if (!(buffer->_2d.linear_buffer = heap_alloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT))))
+        if (!(buffer->_2d.linear_buffer = malloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT))))
             hr = E_OUTOFMEMORY;
 
         if (SUCCEEDED(hr))
@@ -401,7 +401,7 @@ static HRESULT WINAPI d3d9_surface_buffer_Unlock(IMFMediaBuffer *iface)
             IDirect3DSurface9_UnlockRect(buffer->d3d9_surface.surface);
         }
 
-        heap_free(buffer->_2d.linear_buffer);
+        free(buffer->_2d.linear_buffer);
         buffer->_2d.linear_buffer = NULL;
     }
 
@@ -928,7 +928,7 @@ static HRESULT WINAPI dxgi_surface_buffer_Lock(IMFMediaBuffer *iface, BYTE **dat
         hr = MF_E_INVALIDREQUEST;
     else if (!buffer->_2d.linear_buffer)
     {
-        if (!(buffer->_2d.linear_buffer = heap_alloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT))))
+        if (!(buffer->_2d.linear_buffer = malloc(ALIGN_SIZE(buffer->_2d.plane_size, MF_64_BYTE_ALIGNMENT))))
             hr = E_OUTOFMEMORY;
 
         if (SUCCEEDED(hr))
@@ -974,7 +974,7 @@ static HRESULT WINAPI dxgi_surface_buffer_Unlock(IMFMediaBuffer *iface)
                 buffer->_2d.linear_buffer, buffer->_2d.width, buffer->_2d.width, buffer->_2d.height);
         dxgi_surface_buffer_unmap(buffer);
 
-        heap_free(buffer->_2d.linear_buffer);
+        free(buffer->_2d.linear_buffer);
         buffer->_2d.linear_buffer = NULL;
     }
 
@@ -1225,8 +1225,7 @@ static const IMFDXGIBufferVtbl dxgi_buffer_vtbl =
 static HRESULT memory_buffer_init(struct buffer *buffer, DWORD max_length, DWORD alignment,
         const IMFMediaBufferVtbl *vtbl)
 {
-    buffer->data = heap_alloc_zero(ALIGN_SIZE(max_length, alignment));
-    if (!buffer->data)
+    if (!(buffer->data = calloc(1, ALIGN_SIZE(max_length, alignment))))
         return E_OUTOFMEMORY;
 
     buffer->IMFMediaBuffer_iface.lpVtbl = vtbl;
@@ -1248,14 +1247,13 @@ static HRESULT create_1d_buffer(DWORD max_length, DWORD alignment, IMFMediaBuffe
 
     *buffer = NULL;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     hr = memory_buffer_init(object, max_length, alignment, &memory_1d_buffer_vtbl);
     if (FAILED(hr))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -1291,8 +1289,7 @@ static HRESULT create_2d_buffer(DWORD width, DWORD height, DWORD fourcc, BOOL bo
     if (FAILED(hr = MFGetPlaneSize(fourcc, width, height, &plane_size)))
         return hr;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     switch (fourcc)
@@ -1326,7 +1323,7 @@ static HRESULT create_2d_buffer(DWORD width, DWORD height, DWORD fourcc, BOOL bo
 
     if (FAILED(hr = memory_buffer_init(object, max_length, MF_1_BYTE_ALIGNMENT, &memory_1d_2d_buffer_vtbl)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -1360,8 +1357,7 @@ static HRESULT create_d3d9_surface_buffer(IUnknown *surface, BOOL bottom_up, IMF
     if (!(stride = mf_format_get_stride(&subtype, desc.Width, &is_yuv)))
         return MF_E_INVALIDMEDIATYPE;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFMediaBuffer_iface.lpVtbl = &d3d9_surface_1d_buffer_vtbl;
@@ -1412,8 +1408,7 @@ static HRESULT create_dxgi_surface_buffer(IUnknown *surface, unsigned int sub_re
         return MF_E_INVALIDMEDIATYPE;
     }
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
     {
         ID3D11Texture2D_Release(texture);
         return E_OUTOFMEMORY;
diff --git a/dlls/mfplat/main.c b/dlls/mfplat/main.c
index c8d74b5d42c..1fc65f54ea2 100644
--- a/dlls/mfplat/main.c
+++ b/dlls/mfplat/main.c
@@ -47,27 +47,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(mfplat);
 
-static HRESULT heap_strdupW(const WCHAR *str, WCHAR **dest)
-{
-    HRESULT hr = S_OK;
-
-    if (str)
-    {
-        unsigned int size;
-
-        size = (lstrlenW(str) + 1) * sizeof(WCHAR);
-        *dest = heap_alloc(size);
-        if (*dest)
-            memcpy(*dest, str, size);
-        else
-            hr = E_OUTOFMEMORY;
-    }
-    else
-        *dest = NULL;
-
-    return hr;
-}
-
 struct local_handler
 {
     struct list entry;
@@ -204,7 +183,7 @@ static ULONG WINAPI transform_activate_Release(IMFActivate *iface)
             IClassFactory_Release(activate->factory);
         if (activate->transform)
             IMFTransform_Release(activate->transform);
-        heap_free(activate);
+        free(activate);
     }
 
     return refcount;
@@ -598,13 +577,12 @@ static HRESULT create_transform_activate(IClassFactory *factory, IMFActivate **a
     struct transform_activate *object;
     HRESULT hr;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -745,14 +723,14 @@ static HRESULT register_transform(const CLSID *clsid, const WCHAR *name, UINT32
     {
         if (SUCCEEDED(hr = MFGetAttributesAsBlobSize(attributes, &size)))
         {
-            if ((blob = heap_alloc(size)))
+            if ((blob = malloc(size)))
             {
                 if (SUCCEEDED(hr = MFGetAttributesAsBlob(attributes, blob, size)))
                 {
                     if ((ret = RegSetValueExW(hclsid, L"Attributes", 0, REG_BINARY, blob, size)))
                         hr = HRESULT_FROM_WIN32(ret);
                 }
-                heap_free(blob);
+                free(blob);
             }
             else
                 hr = E_OUTOFMEMORY;
@@ -813,10 +791,10 @@ static void release_mft_registration(struct mft_registration *mft)
 {
     if (mft->factory)
         IClassFactory_Release(mft->factory);
-    heap_free(mft->name);
-    heap_free(mft->input_types);
-    heap_free(mft->output_types);
-    heap_free(mft);
+    free(mft->name);
+    free(mft->input_types);
+    free(mft->output_types);
+    free(mft);
 }
 
 static HRESULT mft_register_local(IClassFactory *factory, REFCLSID clsid, REFGUID category, LPCWSTR name, UINT32 flags,
@@ -824,7 +802,7 @@ static HRESULT mft_register_local(IClassFactory *factory, REFCLSID clsid, REFGUI
         const MFT_REGISTER_TYPE_INFO *output_types)
 {
     struct mft_registration *mft, *cur, *unreg_mft = NULL;
-    HRESULT hr;
+    HRESULT hr = S_OK;
 
     if (!factory && !clsid)
     {
@@ -832,8 +810,7 @@ static HRESULT mft_register_local(IClassFactory *factory, REFCLSID clsid, REFGUI
         return E_FAIL;
     }
 
-    mft = heap_alloc_zero(sizeof(*mft));
-    if (!mft)
+    if (!(mft = calloc(1, sizeof(*mft))))
         return E_OUTOFMEMORY;
 
     mft->factory = factory;
@@ -846,13 +823,16 @@ static HRESULT mft_register_local(IClassFactory *factory, REFCLSID clsid, REFGUI
         flags |= MFT_ENUM_FLAG_SYNCMFT;
     mft->flags = flags;
     mft->local = TRUE;
-    if (FAILED(hr = heap_strdupW(name, &mft->name)))
+    if (name && !(mft->name = wcsdup(name)))
+    {
+        hr = E_OUTOFMEMORY;
         goto failed;
+    }
 
     if (input_count && input_types)
     {
         mft->input_types_count = input_count;
-        if (!(mft->input_types = heap_calloc(mft->input_types_count, sizeof(*input_types))))
+        if (!(mft->input_types = calloc(mft->input_types_count, sizeof(*input_types))))
         {
             hr = E_OUTOFMEMORY;
             goto failed;
@@ -863,7 +843,7 @@ static HRESULT mft_register_local(IClassFactory *factory, REFCLSID clsid, REFGUI
     if (output_count && output_types)
     {
         mft->output_types_count = output_count;
-        if (!(mft->output_types = heap_calloc(mft->output_types_count, sizeof(*output_types))))
+        if (!(mft->output_types = calloc(mft->output_types_count, sizeof(*output_types))))
         {
             hr = E_OUTOFMEMORY;
             goto failed;
@@ -1063,14 +1043,14 @@ static void mft_get_reg_type_info(const WCHAR *clsidW, const WCHAR *typeW, MFT_R
     if (!size || size % sizeof(**type))
         goto out;
 
-    if (!(*type = heap_alloc(size)))
+    if (!(*type = malloc(size)))
         goto out;
 
     *count = size / sizeof(**type);
 
     if (RegQueryValueExW(hfilter, typeW, NULL, &reg_type, (BYTE *)*type, &size))
     {
-        heap_free(*type);
+        free(*type);
         *type = NULL;
         *count = 0;
     }
@@ -1139,12 +1119,12 @@ static HRESULT mft_collect_machine_reg(struct list *mfts, const GUID *category,
 
         if (!mft_is_type_info_match(&mft, category, flags, plugin_control, input_type, output_type))
         {
-            heap_free(mft.input_types);
-            heap_free(mft.output_types);
+            free(mft.input_types);
+            free(mft.output_types);
             goto next;
         }
 
-        cur = heap_alloc(sizeof(*cur));
+        cur = malloc(sizeof(*cur));
         /* Reuse allocated type arrays. */
         *cur = mft;
         list_add_tail(mfts, &cur->entry);
@@ -1216,7 +1196,7 @@ static HRESULT mft_enum(GUID category, UINT32 flags, const MFT_REGISTER_TYPE_INF
         {
             if (mft_is_type_info_match(local, &category, flags, plugin_control, input_type, output_type))
             {
-                mft = heap_alloc_zero(sizeof(*mft));
+                mft = calloc(1, sizeof(*mft));
 
                 mft->clsid = local->clsid;
                 mft->factory = local->factory;
@@ -2185,7 +2165,7 @@ static ULONG WINAPI mfattributes_Release(IMFAttributes *iface)
     if (!refcount)
     {
         clear_attributes_object(attributes);
-        heap_free(attributes);
+        free(attributes);
     }
 
     return refcount;
@@ -2671,7 +2651,7 @@ HRESULT attributes_DeleteAllItems(struct attributes *attributes)
     {
         PropVariantClear(&attributes->attributes[--attributes->count].value);
     }
-    heap_free(attributes->attributes);
+    free(attributes->attributes);
     attributes->attributes = NULL;
     attributes->capacity = 0;
 
@@ -3147,7 +3127,7 @@ void clear_attributes_object(struct attributes *object)
 
     for (i = 0; i < object->count; i++)
         PropVariantClear(&object->attributes[i].value);
-    heap_free(object->attributes);
+    free(object->attributes);
 
     DeleteCriticalSection(&object->cs);
 }
@@ -3162,13 +3142,12 @@ HRESULT WINAPI MFCreateAttributes(IMFAttributes **attributes, UINT32 size)
 
     TRACE("%p, %d\n", attributes, size);
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(object, size)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
     *attributes = &object->IMFAttributes_iface;
@@ -3575,7 +3554,7 @@ static ULONG WINAPI async_stream_op_Release(IUnknown *iface)
     {
         if (op->caller)
             IMFAsyncResult_Release(op->caller);
-        heap_free(op);
+        free(op);
     }
 
     return refcount;
@@ -3595,7 +3574,7 @@ static HRESULT bytestream_create_io_request(struct bytestream *stream, enum asyn
     IRtwqAsyncResult *request;
     HRESULT hr;
 
-    op = heap_alloc(sizeof(*op));
+    op = malloc(sizeof(*op));
     if (!op)
         return E_OUTOFMEMORY;
 
@@ -3757,7 +3736,7 @@ static ULONG WINAPI bytestream_Release(IMFByteStream *iface)
             IStream_Release(stream->stream);
         if (stream->hfile)
             CloseHandle(stream->hfile);
-        heap_free(stream);
+        free(stream);
     }
 
     return refcount;
@@ -4320,13 +4299,12 @@ HRESULT WINAPI MFCreateMFByteStreamOnStream(IStream *stream, IMFByteStream **byt
 
     TRACE("%p, %p.\n", stream, bytestream);
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -4485,8 +4463,7 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open
     if(file == INVALID_HANDLE_VALUE)
         return HRESULT_FROM_WIN32(GetLastError());
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
     {
         CloseHandle(file);
         return E_OUTOFMEMORY;
@@ -4495,7 +4472,7 @@ HRESULT WINAPI MFCreateFile(MF_FILE_ACCESSMODE accessmode, MF_FILE_OPENMODE open
     if (FAILED(hr = init_attributes_object(&object->attributes, 2)))
     {
         CloseHandle(file);
-        heap_free(object);
+        free(object);
         return hr;
     }
     object->IMFByteStream_iface.lpVtbl = &bytestream_file_vtbl;
@@ -4668,7 +4645,7 @@ static ULONG WINAPI bytestream_wrapper_Release(IMFByteStream *iface)
         if (wrapper->attributes)
             IMFAttributes_Release(wrapper->attributes);
         IMFByteStream_Release(wrapper->stream);
-        heap_free(wrapper);
+        free(wrapper);
     }
 
     return refcount;
@@ -5545,8 +5522,7 @@ HRESULT WINAPI MFCreateMFByteStreamWrapper(IMFByteStream *stream, IMFByteStream
 
     TRACE("%p, %p.\n", stream, wrapper);
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFByteStreamCacheControl_iface.lpVtbl = &bytestream_wrapper_cache_control_vtbl;
@@ -5738,7 +5714,7 @@ static HRESULT resolver_handler_end_create(struct source_resolver *resolver, enu
         IMFSchemeHandler *scheme_handler;
     } handler;
 
-    if (!(queued_result = heap_alloc_zero(sizeof(*queued_result))))
+    if (!(queued_result = calloc(1, sizeof(*queued_result))))
         return E_OUTOFMEMORY;
 
     queued_result->origin = origin;
@@ -5823,7 +5799,7 @@ static ULONG WINAPI resolver_cancel_object_Release(IUnknown *iface)
         if (object->cancel_cookie)
             IUnknown_Release(object->cancel_cookie);
         IUnknown_Release(object->u.handler);
-        heap_free(object);
+        free(object);
     }
 
     return refcount;
@@ -5850,8 +5826,7 @@ static HRESULT resolver_create_cancel_object(IUnknown *handler, enum resolved_ob
 {
     struct resolver_cancel_object *object;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IUnknown_iface.lpVtbl = &resolver_cancel_object_vtbl;
@@ -6153,7 +6128,7 @@ static HRESULT resolver_get_scheme_handler(const WCHAR *url, DWORD flags, IMFSch
     }
 
     len = ptr - url;
-    scheme = heap_alloc((len + 1) * sizeof(WCHAR));
+    scheme = malloc((len + 1) * sizeof(WCHAR));
     if (!scheme)
         return E_OUTOFMEMORY;
 
@@ -6164,7 +6139,7 @@ static HRESULT resolver_get_scheme_handler(const WCHAR *url, DWORD flags, IMFSch
     if (FAILED(hr) && url != fileschemeW)
         hr = resolver_create_scheme_handler(fileschemeW, flags, handler);
 
-    heap_free(scheme);
+    free(scheme);
 
     return hr;
 }
@@ -6202,7 +6177,7 @@ static HRESULT resolver_end_create_object(struct source_resolver *resolver, enum
         hr = queued_result->hr;
         if (queued_result->inner_result)
             IRtwqAsyncResult_Release(queued_result->inner_result);
-        heap_free(queued_result);
+        free(queued_result);
     }
     else
         hr = E_UNEXPECTED;
@@ -6257,10 +6232,10 @@ static ULONG WINAPI source_resolver_Release(IMFSourceResolver *iface)
             if (result->object)
                 IUnknown_Release(result->object);
             list_remove(&result->entry);
-            heap_free(result);
+            free(result);
         }
         DeleteCriticalSection(&resolver->cs);
-        heap_free(resolver);
+        free(resolver);
     }
 
     return refcount;
@@ -6488,8 +6463,7 @@ HRESULT WINAPI MFCreateSourceResolver(IMFSourceResolver **resolver)
     if (!resolver)
         return E_POINTER;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFSourceResolver_iface.lpVtbl = &mfsourceresolvervtbl;
@@ -6564,7 +6538,7 @@ static ULONG WINAPI mfmediaevent_Release(IMFMediaEvent *iface)
     {
         clear_attributes_object(&event->attributes);
         PropVariantClear(&event->value);
-        heap_free(event);
+        free(event);
     }
 
     return refcount;
@@ -6941,13 +6915,13 @@ HRESULT WINAPI MFCreateMediaEvent(MediaEventType type, REFGUID extended_type, HR
     TRACE("%s, %s, %#x, %s, %p.\n", debugstr_eventid(type), debugstr_guid(extended_type), status,
             debugstr_propvar(value), event);
 
-    object = heap_alloc(sizeof(*object));
+    object = malloc(sizeof(*object));
     if (!object)
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
     object->IMFMediaEvent_iface.lpVtbl = &mfmediaevent_vtbl;
@@ -7003,7 +6977,7 @@ static IMFMediaEvent *queue_pop_event(struct event_queue *queue)
     queued_event = LIST_ENTRY(head, struct queued_event, entry);
     event = queued_event->event;
     list_remove(&queued_event->entry);
-    heap_free(queued_event);
+    free(queued_event);
     return event;
 }
 
@@ -7063,7 +7037,7 @@ static ULONG WINAPI eventqueue_Release(IMFMediaEventQueue *iface)
     {
         event_queue_cleanup(queue);
         DeleteCriticalSection(&queue->cs);
-        heap_free(queue);
+        free(queue);
     }
 
     return refcount;
@@ -7179,7 +7153,7 @@ static HRESULT eventqueue_queue_event(struct event_queue *queue, IMFMediaEvent *
     struct queued_event *queued_event;
     HRESULT hr = S_OK;
 
-    queued_event = heap_alloc(sizeof(*queued_event));
+    queued_event = malloc(sizeof(*queued_event));
     if (!queued_event)
         return E_OUTOFMEMORY;
 
@@ -7199,7 +7173,7 @@ static HRESULT eventqueue_queue_event(struct event_queue *queue, IMFMediaEvent *
     LeaveCriticalSection(&queue->cs);
 
     if (FAILED(hr))
-        heap_free(queued_event);
+        free(queued_event);
 
     WakeAllConditionVariable(&queue->update_event);
 
@@ -7298,8 +7272,7 @@ HRESULT WINAPI MFCreateEventQueue(IMFMediaEventQueue **queue)
 
     TRACE("%p\n", queue);
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFMediaEventQueue_iface.lpVtbl = &eventqueuevtbl;
@@ -7337,7 +7310,7 @@ static void collection_clear(struct collection *collection)
             IUnknown_Release(collection->elements[i]);
     }
 
-    heap_free(collection->elements);
+    free(collection->elements);
     collection->elements = NULL;
     collection->count = 0;
     collection->capacity = 0;
@@ -7380,8 +7353,8 @@ static ULONG WINAPI collection_Release(IMFCollection *iface)
     if (!refcount)
     {
         collection_clear(collection);
-        heap_free(collection->elements);
-        heap_free(collection);
+        free(collection->elements);
+        free(collection);
     }
 
     return refcount;
@@ -7527,8 +7500,7 @@ HRESULT WINAPI MFCreateCollection(IMFCollection **collection)
     if (!collection)
         return E_POINTER;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFCollection_iface.lpVtbl = &mfcollectionvtbl;
@@ -7602,7 +7574,7 @@ static ULONG WINAPI system_clock_Release(IMFClock *iface)
     TRACE("%p, refcount %u.\n", iface, refcount);
 
     if (!refcount)
-        heap_free(clock);
+        free(clock);
 
     return refcount;
 }
@@ -7676,7 +7648,7 @@ static HRESULT create_system_clock(IMFClock **clock)
 {
     struct system_clock *object;
 
-    if (!(object = heap_alloc(sizeof(*object))))
+    if (!(object = malloc(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFClock_iface.lpVtbl = &system_clock_vtbl;
@@ -7735,7 +7707,7 @@ static ULONG WINAPI system_time_source_Release(IMFPresentationTimeSource *iface)
         if (source->clock)
             IMFClock_Release(source->clock);
         DeleteCriticalSection(&source->cs);
-        heap_free(source);
+        free(source);
     }
 
     return refcount;
@@ -8025,7 +7997,7 @@ HRESULT WINAPI MFCreateSystemTimeSource(IMFPresentationTimeSource **time_source)
 
     TRACE("%p.\n", time_source);
 
-    object = heap_alloc_zero(sizeof(*object));
+    object = calloc(1, sizeof(*object));
     if (!object)
         return E_OUTOFMEMORY;
 
@@ -8105,8 +8077,8 @@ static ULONG WINAPI async_create_file_callback_Release(IRtwqAsyncCallback *iface
 
     if (!refcount)
     {
-        heap_free(async->path);
-        heap_free(async);
+        free(async->path);
+        free(async);
     }
 
     return refcount;
@@ -8131,7 +8103,7 @@ static HRESULT WINAPI async_create_file_callback_Invoke(IRtwqAsyncCallback *ifac
     {
         struct async_create_file_result *result_item;
 
-        result_item = heap_alloc(sizeof(*result_item));
+        result_item = malloc(sizeof(*result_item));
         if (result_item)
         {
             result_item->result = caller;
@@ -8182,8 +8154,7 @@ HRESULT WINAPI MFBeginCreateFile(MF_FILE_ACCESSMODE access_mode, MF_FILE_OPENMOD
     if (FAILED(hr = RtwqCreateAsyncResult(NULL, (IRtwqAsyncCallback *)callback, state, &caller)))
         return hr;
 
-    async = heap_alloc(sizeof(*async));
-    if (!async)
+    if (!(async = malloc(sizeof(*async))))
     {
         hr = E_OUTOFMEMORY;
         goto failed;
@@ -8194,8 +8165,11 @@ HRESULT WINAPI MFBeginCreateFile(MF_FILE_ACCESSMODE access_mode, MF_FILE_OPENMOD
     async->access_mode = access_mode;
     async->open_mode = open_mode;
     async->flags = flags;
-    if (FAILED(hr = heap_strdupW(path, &async->path)))
+    if (!(async->path = wcsdup(path)))
+    {
+        hr = E_OUTOFMEMORY;
         goto failed;
+    }
 
     hr = RtwqCreateAsyncResult(NULL, &async->IRtwqAsyncCallback_iface, (IUnknown *)caller, &item);
     if (FAILED(hr))
@@ -8240,7 +8214,7 @@ static HRESULT async_create_file_pull_result(IUnknown *unk, IMFByteStream **stre
             *stream = item->stream;
             IRtwqAsyncResult_Release(item->result);
             list_remove(&item->entry);
-            heap_free(item);
+            free(item);
             break;
         }
     }
@@ -8289,20 +8263,19 @@ HRESULT WINAPI MFCancelCreateFile(IUnknown *cancel_cookie)
 HRESULT WINAPI MFRegisterLocalSchemeHandler(const WCHAR *scheme, IMFActivate *activate)
 {
     struct local_handler *handler;
-    HRESULT hr;
 
     TRACE("%s, %p.\n", debugstr_w(scheme), activate);
 
     if (!scheme || !activate)
         return E_INVALIDARG;
 
-    if (!(handler = heap_alloc(sizeof(*handler))))
+    if (!(handler = malloc(sizeof(*handler))))
         return E_OUTOFMEMORY;
 
-    if (FAILED(hr = heap_strdupW(scheme, &handler->u.scheme)))
+    if (!(handler->u.scheme = wcsdup(scheme)))
     {
-        heap_free(handler);
-        return hr;
+        free(handler);
+        return E_OUTOFMEMORY;
     }
     handler->activate = activate;
     IMFActivate_AddRef(handler->activate);
@@ -8320,35 +8293,32 @@ HRESULT WINAPI MFRegisterLocalSchemeHandler(const WCHAR *scheme, IMFActivate *ac
 HRESULT WINAPI MFRegisterLocalByteStreamHandler(const WCHAR *extension, const WCHAR *mime, IMFActivate *activate)
 {
     struct local_handler *handler;
-    HRESULT hr;
 
     TRACE("%s, %s, %p.\n", debugstr_w(extension), debugstr_w(mime), activate);
 
     if ((!extension && !mime) || !activate)
         return E_INVALIDARG;
 
-    if (!(handler = heap_alloc_zero(sizeof(*handler))))
+    if (!(handler = calloc(1, sizeof(*handler))))
         return E_OUTOFMEMORY;
 
-    hr = heap_strdupW(extension, &handler->u.bytestream.extension);
-    if (SUCCEEDED(hr))
-        hr = heap_strdupW(mime, &handler->u.bytestream.mime);
-
-    if (FAILED(hr))
+    if (extension && !(handler->u.bytestream.extension = wcsdup(extension)))
+        goto failed;
+    if (mime && !(handler->u.bytestream.mime = wcsdup(mime)))
         goto failed;
 
     EnterCriticalSection(&local_handlers_section);
     list_add_head(&local_bytestream_handlers, &handler->entry);
     LeaveCriticalSection(&local_handlers_section);
 
-    return hr;
+    return S_OK;
 
 failed:
-    heap_free(handler->u.bytestream.extension);
-    heap_free(handler->u.bytestream.mime);
-    heap_free(handler);
+    free(handler->u.bytestream.extension);
+    free(handler->u.bytestream.mime);
+    free(handler);
 
-    return hr;
+    return E_OUTOFMEMORY;
 }
 
 struct property_store
@@ -8405,8 +8375,8 @@ static ULONG WINAPI property_store_Release(IPropertyStore *iface)
     if (!refcount)
     {
         DeleteCriticalSection(&store->cs);
-        heap_free(store->values);
-        heap_free(store);
+        free(store->values);
+        free(store);
     }
 
     return refcount;
@@ -8540,7 +8510,7 @@ HRESULT WINAPI CreatePropertyStore(IPropertyStore **store)
     if (!store)
         return E_INVALIDARG;
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IPropertyStore_iface.lpVtbl = &property_store_vtbl;
@@ -8640,8 +8610,8 @@ static ULONG WINAPI dxgi_device_manager_Release(IMFDXGIDeviceManager *iface)
         if (manager->device)
             IDXGIDevice_Release(manager->device);
         DeleteCriticalSection(&manager->cs);
-        heap_free(manager->handles);
-        heap_free(manager);
+        free(manager->handles);
+        free(manager);
     }
 
     return refcount;
@@ -8926,7 +8896,7 @@ HRESULT WINAPI MFCreateDXGIDeviceManager(UINT *token, IMFDXGIDeviceManager **man
     if (!token || !manager)
         return E_POINTER;
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFDXGIDeviceManager_iface.lpVtbl = &dxgi_device_manager_vtbl;
diff --git a/dlls/mfplat/mediatype.c b/dlls/mfplat/mediatype.c
index 92d219f26e1..61f1a75d90b 100644
--- a/dlls/mfplat/mediatype.c
+++ b/dlls/mfplat/mediatype.c
@@ -157,7 +157,7 @@ static ULONG WINAPI mediatype_Release(IMFMediaType *iface)
         clear_attributes_object(&media_type->attributes);
         CoTaskMemFree(media_type->video_format);
         CoTaskMemFree(media_type->audio_format);
-        heap_free(media_type);
+        free(media_type);
     }
 
     return refcount;
@@ -1435,13 +1435,12 @@ static HRESULT create_media_type(struct media_type **ret)
     struct media_type *object;
     HRESULT hr;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
     object->IMFMediaType_iface.lpVtbl = &mediatypevtbl;
@@ -1519,11 +1518,11 @@ static ULONG WINAPI stream_descriptor_Release(IMFStreamDescriptor *iface)
             if (stream_desc->media_types[i])
                 IMFMediaType_Release(stream_desc->media_types[i]);
         }
-        heap_free(stream_desc->media_types);
+        free(stream_desc->media_types);
         if (stream_desc->current_type)
             IMFMediaType_Release(stream_desc->current_type);
         clear_attributes_object(&stream_desc->attributes);
-        heap_free(stream_desc);
+        free(stream_desc);
     }
 
     return refcount;
@@ -2052,19 +2051,18 @@ HRESULT WINAPI MFCreateStreamDescriptor(DWORD identifier, DWORD count,
     if (!count)
         return E_INVALIDARG;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
     object->IMFStreamDescriptor_iface.lpVtbl = &streamdescriptorvtbl;
     object->IMFMediaTypeHandler_iface.lpVtbl = &mediatypehandlervtbl;
     object->identifier = identifier;
-    object->media_types = heap_alloc(count * sizeof(*object->media_types));
+    object->media_types = calloc(count, sizeof(*object->media_types));
     if (!object->media_types)
     {
         IMFStreamDescriptor_Release(&object->IMFStreamDescriptor_iface);
@@ -2127,8 +2125,8 @@ static ULONG WINAPI presentation_descriptor_Release(IMFPresentationDescriptor *i
                 IMFStreamDescriptor_Release(presentation_desc->descriptors[i].descriptor);
         }
         clear_attributes_object(&presentation_desc->attributes);
-        heap_free(presentation_desc->descriptors);
-        heap_free(presentation_desc);
+        free(presentation_desc->descriptors);
+        free(presentation_desc);
     }
 
     return refcount;
@@ -2491,8 +2489,7 @@ static HRESULT WINAPI presentation_descriptor_Clone(IMFPresentationDescriptor *i
 
     TRACE("%p, %p.\n", iface, descriptor);
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     presentation_descriptor_init(object, presentation_desc->count);
@@ -2563,8 +2560,7 @@ static HRESULT presentation_descriptor_init(struct presentation_desc *object, DW
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
         return hr;
     object->IMFPresentationDescriptor_iface.lpVtbl = &presentationdescriptorvtbl;
-    object->descriptors = heap_alloc_zero(count * sizeof(*object->descriptors));
-    if (!object->descriptors)
+    if (!(object->descriptors = calloc(count, sizeof(*object->descriptors))))
     {
         IMFPresentationDescriptor_Release(&object->IMFPresentationDescriptor_iface);
         return E_OUTOFMEMORY;
@@ -2595,13 +2591,12 @@ HRESULT WINAPI MFCreatePresentationDescriptor(DWORD count, IMFStreamDescriptor *
             return E_INVALIDARG;
     }
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = presentation_descriptor_init(object, count)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -2818,7 +2813,7 @@ HRESULT WINAPI MFWrapMediaType(IMFMediaType *original, REFGUID major, REFGUID su
     if (FAILED(hr = MFGetAttributesAsBlobSize((IMFAttributes *)original, &size)))
         return hr;
 
-    if (!(buffer = heap_alloc(size)))
+    if (!(buffer = malloc(size)))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = MFGetAttributesAsBlob((IMFAttributes *)original, buffer, size)))
@@ -2839,7 +2834,7 @@ HRESULT WINAPI MFWrapMediaType(IMFMediaType *original, REFGUID major, REFGUID su
     *ret = mediatype;
 
 failed:
-    heap_free(buffer);
+    free(buffer);
 
     return hr;
 }
diff --git a/dlls/mfplat/mfplat_private.h b/dlls/mfplat/mfplat_private.h
index 117907bb1a9..b646d9e7cbb 100644
--- a/dlls/mfplat/mfplat_private.h
+++ b/dlls/mfplat/mfplat_private.h
@@ -25,7 +25,6 @@
 #include "mferror.h"
 #include "d3d9types.h"
 
-#include "wine/heap.h"
 #include "wine/debug.h"
 
 struct attribute
@@ -106,7 +105,7 @@ static inline BOOL mf_array_reserve(void **elements, size_t *capacity, size_t co
     if (new_capacity < count)
         new_capacity = max_capacity;
 
-    if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
+    if (!(new_elements = realloc(*elements, new_capacity * size)))
         return FALSE;
 
     *elements = new_elements;
diff --git a/dlls/mfplat/sample.c b/dlls/mfplat/sample.c
index cdd3d897169..93c5f923cc2 100644
--- a/dlls/mfplat/sample.c
+++ b/dlls/mfplat/sample.c
@@ -162,8 +162,8 @@ static void release_sample_object(struct sample *sample)
     for (i = 0; i < sample->buffer_count; ++i)
         IMFMediaBuffer_Release(sample->buffers[i]);
     clear_attributes_object(&sample->attributes);
-    heap_free(sample->buffers);
-    heap_free(sample);
+    free(sample->buffers);
+    free(sample);
 }
 
 static ULONG WINAPI sample_Release(IMFSample *iface)
@@ -1020,13 +1020,12 @@ HRESULT WINAPI MFCreateSample(IMFSample **sample)
 
     TRACE("%p.\n", sample);
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -1049,13 +1048,12 @@ HRESULT WINAPI MFCreateTrackedSample(IMFTrackedSample **sample)
 
     TRACE("%p.\n", sample);
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = init_attributes_object(&object->attributes, 0)))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -1112,13 +1110,13 @@ static void sample_allocator_release_samples(struct sample_allocator *allocator)
     {
         list_remove(&iter->entry);
         IMFSample_Release(iter->sample);
-        heap_free(iter);
+        free(iter);
     }
 
     LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &allocator->used_samples, struct queued_sample, entry)
     {
         list_remove(&iter->entry);
-        heap_free(iter);
+        free(iter);
     }
 
     allocator->free_sample_count = 0;
@@ -1183,7 +1181,7 @@ static ULONG WINAPI sample_allocator_Release(IMFVideoSampleAllocatorEx *iface)
         sample_allocator_set_attributes(allocator, NULL);
         sample_allocator_release_samples(allocator);
         DeleteCriticalSection(&allocator->cs);
-        heap_free(allocator);
+        free(allocator);
     }
 
     return refcount;
@@ -1308,7 +1306,7 @@ static void sample_allocator_release_surface_service(struct sample_allocator *al
 static HRESULT sample_allocator_allocate_sample(struct sample_allocator *allocator, const struct surface_service *service,
         IMFSample **sample)
 {
-    struct queued_sample *queued_sample = heap_alloc(sizeof(*queued_sample));
+    struct queued_sample *queued_sample = malloc(sizeof(*queued_sample));
     IMFTrackedSample *tracked_sample;
     IMFMediaBuffer *buffer;
     unsigned int i;
@@ -1445,7 +1443,7 @@ static HRESULT sample_allocator_initialize(struct sample_allocator *allocator, u
 
         if (SUCCEEDED(hr = sample_allocator_allocate_sample(allocator, &service, &sample)))
         {
-            queued_sample = heap_alloc(sizeof(*queued_sample));
+            queued_sample = malloc(sizeof(*queued_sample));
             queued_sample->sample = sample;
             list_add_tail(&allocator->free_samples, &queued_sample->entry);
             allocator->free_sample_count++;
@@ -1534,7 +1532,7 @@ static HRESULT WINAPI sample_allocator_AllocateSample(IMFVideoSampleAllocatorEx
             {
                 if (SUCCEEDED(hr = sample_allocator_track_sample(allocator, sample)))
                 {
-                    struct queued_sample *queued_sample = heap_alloc(sizeof(*queued_sample));
+                    struct queued_sample *queued_sample = malloc(sizeof(*queued_sample));
 
                     queued_sample->sample = sample;
                     list_add_tail(&allocator->used_samples, &queued_sample->entry);
@@ -1738,7 +1736,7 @@ HRESULT WINAPI MFCreateVideoSampleAllocatorEx(REFIID riid, void **obj)
 
     TRACE("%s, %p.\n", debugstr_guid(riid), obj);
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IMFVideoSampleAllocatorEx_iface.lpVtbl = &sample_allocator_vtbl;
-- 
2.30.2




More information about the wine-devel mailing list