[PATCH 5/5] dwrite: Use CRT allocation functions.

Nikolay Sivov nsivov at codeweavers.com
Thu Dec 2 06:37:19 CST 2021


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/dwrite/analyzer.c       | 123 +++++++------
 dlls/dwrite/bidi.c           |  41 ++---
 dlls/dwrite/dwrite_private.h |  24 +--
 dlls/dwrite/font.c           | 337 ++++++++++++++++++-----------------
 dlls/dwrite/gdiinterop.c     |  34 ++--
 dlls/dwrite/layout.c         | 251 +++++++++++++-------------
 dlls/dwrite/main.c           |  87 +++++----
 dlls/dwrite/opentype.c       |  38 ++--
 dlls/dwrite/shape.c          |  11 +-
 9 files changed, 461 insertions(+), 485 deletions(-)

diff --git a/dlls/dwrite/analyzer.c b/dlls/dwrite/analyzer.c
index e8a30a7ae45..7112ca71932 100644
--- a/dlls/dwrite/analyzer.c
+++ b/dlls/dwrite/analyzer.c
@@ -456,8 +456,7 @@ static HRESULT analyze_linebreaks(const WCHAR *text, UINT32 count, DWRITE_LINE_B
     short *break_class;
     int i, j;
 
-    break_class = heap_calloc(count, sizeof(*break_class));
-    if (!break_class)
+    if (!(break_class = calloc(count, sizeof(*break_class))))
         return E_OUTOFMEMORY;
 
     state.breakpoints = breakpoints;
@@ -817,7 +816,7 @@ static HRESULT analyze_linebreaks(const WCHAR *text, UINT32 count, DWRITE_LINE_B
         set_break_condition(i, BreakConditionAfter, DWRITE_BREAK_CONDITION_CAN_BREAK, &state);
     }
 
-    heap_free(break_class);
+    free(break_class);
     return S_OK;
 }
 
@@ -866,7 +865,7 @@ static HRESULT get_text_source_ptr(IDWriteTextAnalysisSource *source, UINT32 pos
     if (len < length) {
         UINT32 read;
 
-        *buff = heap_alloc(length*sizeof(WCHAR));
+        *buff = malloc(length * sizeof(WCHAR));
         if (!*buff)
             return E_OUTOFMEMORY;
         memcpy(*buff, *text, len*sizeof(WCHAR));
@@ -876,8 +875,9 @@ static HRESULT get_text_source_ptr(IDWriteTextAnalysisSource *source, UINT32 pos
             *text = NULL;
             len = 0;
             hr = IDWriteTextAnalysisSource_GetTextAtPosition(source, read, text, &len);
-            if (FAILED(hr)) {
-                heap_free(*buff);
+            if (FAILED(hr))
+            {
+                free(*buff);
                 return hr;
             }
             memcpy(*buff + read, *text, min(len, length-read)*sizeof(WCHAR));
@@ -907,7 +907,7 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeScript(IDWriteTextAnalyzer2 *ifa
         return hr;
 
     hr = analyze_script(text, position, length, sink);
-    heap_free(buff);
+    free(buff);
 
     return hr;
 }
@@ -931,8 +931,8 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer2 *iface
     if (FAILED(hr))
         return hr;
 
-    levels = heap_calloc(length, sizeof(*levels));
-    explicit = heap_calloc(length, sizeof(*explicit));
+    levels = calloc(length, sizeof(*levels));
+    explicit = calloc(length, sizeof(*explicit));
 
     if (!levels || !explicit) {
         hr = E_OUTOFMEMORY;
@@ -967,9 +967,9 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeBidi(IDWriteTextAnalyzer2 *iface
     hr = IDWriteTextAnalysisSink_SetBidiLevel(sink, pos, seq_length, explicit_level, level);
 
 done:
-    heap_free(explicit);
-    heap_free(levels);
-    heap_free(buff);
+    free(explicit);
+    free(levels);
+    free(buff);
 
     return hr;
 }
@@ -1007,8 +1007,7 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnaly
     if (len < length) {
         UINT32 read;
 
-        buff = heap_calloc(length, sizeof(*buff));
-        if (!buff)
+        if (!(buff = calloc(length, sizeof(*buff))))
             return E_OUTOFMEMORY;
         memcpy(buff, text, len*sizeof(WCHAR));
         read = len;
@@ -1026,8 +1025,8 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnaly
         text = buff;
     }
 
-    breakpoints = heap_calloc(length, sizeof(*breakpoints));
-    if (!breakpoints) {
+    if (!(breakpoints = calloc(length, sizeof(*breakpoints))))
+    {
         hr = E_OUTOFMEMORY;
         goto done;
     }
@@ -1039,8 +1038,8 @@ static HRESULT WINAPI dwritetextanalyzer_AnalyzeLineBreakpoints(IDWriteTextAnaly
     hr = IDWriteTextAnalysisSink_SetLineBreakpoints(sink, position, length, breakpoints);
 
 done:
-    heap_free(breakpoints);
-    heap_free(buff);
+    free(breakpoints);
+    free(buff);
 
     return hr;
 }
@@ -1178,8 +1177,8 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphs(IDWriteTextAnalyzer2 *iface,
     context.length = length;
     context.is_rtl = is_rtl;
     context.is_sideways = is_sideways;
-    context.u.subst.glyphs = heap_calloc(glyph_count, sizeof(*glyphs));
-    context.u.subst.glyph_props = heap_calloc(glyph_count, sizeof(*glyph_props));
+    context.u.subst.glyphs = calloc(glyph_count, sizeof(*glyphs));
+    context.u.subst.glyph_props = calloc(glyph_count, sizeof(*glyph_props));
     context.u.subst.text_props = text_props;
     context.u.subst.clustermap = clustermap;
     context.u.subst.max_glyph_count = max_glyph_count;
@@ -1189,7 +1188,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphs(IDWriteTextAnalyzer2 *iface,
     context.user_features.features = features;
     context.user_features.range_lengths = feature_range_lengths;
     context.user_features.range_count = feature_ranges;
-    context.glyph_infos = heap_calloc(glyph_count, sizeof(*context.glyph_infos));
+    context.glyph_infos = calloc(glyph_count, sizeof(*context.glyph_infos));
     context.table = &context.cache->gsub;
 
     *actual_glyph_count = 0;
@@ -1210,9 +1209,9 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphs(IDWriteTextAnalyzer2 *iface,
     }
 
 failed:
-    heap_free(context.u.subst.glyph_props);
-    heap_free(context.u.subst.glyphs);
-    heap_free(context.glyph_infos);
+    free(context.u.subst.glyph_props);
+    free(context.u.subst.glyphs);
+    free(context.glyph_infos);
 
     return hr;
 }
@@ -1272,7 +1271,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphPlacements(IDWriteTextAnalyzer2
     context.user_features.features = features;
     context.user_features.range_lengths = feature_range_lengths;
     context.user_features.range_count = feature_ranges;
-    context.glyph_infos = heap_calloc(glyph_count, sizeof(*context.glyph_infos));
+    context.glyph_infos = calloc(glyph_count, sizeof(*context.glyph_infos));
     context.table = &context.cache->gpos;
 
     if (!context.glyph_infos)
@@ -1285,7 +1284,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGlyphPlacements(IDWriteTextAnalyzer2
     hr = shape_get_positions(&context, scriptprops->scripttags);
 
 failed:
-    heap_free(context.glyph_infos);
+    free(context.glyph_infos);
 
     return hr;
 }
@@ -1349,7 +1348,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGdiCompatibleGlyphPlacements(IDWrite
     context.user_features.features = features;
     context.user_features.range_lengths = feature_range_lengths;
     context.user_features.range_count = feature_ranges;
-    context.glyph_infos = heap_calloc(glyph_count, sizeof(*context.glyph_infos));
+    context.glyph_infos = calloc(glyph_count, sizeof(*context.glyph_infos));
     context.table = &context.cache->gpos;
 
     if (!context.glyph_infos)
@@ -1362,7 +1361,7 @@ static HRESULT WINAPI dwritetextanalyzer_GetGdiCompatibleGlyphPlacements(IDWrite
     hr = shape_get_positions(&context, scriptprops->scripttags);
 
 failed:
-    heap_free(context.glyph_infos);
+    free(context.glyph_infos);
 
     return hr;
 }
@@ -1398,8 +1397,7 @@ static HRESULT apply_cluster_spacing(float leading_spacing, float trailing_spaci
             break;
     }
 
-    deltas = heap_calloc(end - start + 1, sizeof(*deltas));
-    if (!deltas)
+    if (!(deltas = calloc(end - start + 1, sizeof(*deltas))))
         return E_OUTOFMEMORY;
 
     /* Cluster advance, note that properties are ignored. */
@@ -1479,7 +1477,7 @@ static HRESULT apply_cluster_spacing(float leading_spacing, float trailing_spaci
                 modified_advances[i - 1];
     }
 
-    heap_free(deltas);
+    free(deltas);
 
     return S_OK;
 }
@@ -1693,16 +1691,18 @@ static HRESULT WINAPI dwritetextanalyzer1_GetTextComplexity(IDWriteTextAnalyzer2
     *len_read = i;
 
     /* fetch indices */
-    if (*is_simple && indices) {
-        UINT32 *codepoints = heap_calloc(*len_read, sizeof(*codepoints));
-        if (!codepoints)
+    if (*is_simple && indices)
+    {
+        UINT32 *codepoints;
+
+        if (!(codepoints = calloc(*len_read, sizeof(*codepoints))))
             return E_OUTOFMEMORY;
 
         for (i = 0; i < *len_read; i++)
             codepoints[i] = text[i];
 
         hr = IDWriteFontFace_GetGlyphIndices(face, codepoints, *len_read, indices);
-        heap_free(codepoints);
+        free(codepoints);
     }
 
     return hr;
@@ -1830,14 +1830,14 @@ static HRESULT WINAPI dwritetextanalyzer2_CheckTypographicFeature(IDWriteTextAna
 
     context.cache = fontface_get_shaping_cache(font_obj);
     context.language_tag = get_opentype_language(locale);
-    if (!(context.glyph_infos = heap_calloc(glyph_count, sizeof(*context.glyph_infos))))
+    if (!(context.glyph_infos = calloc(glyph_count, sizeof(*context.glyph_infos))))
         return E_OUTOFMEMORY;
 
     props = &dwritescripts_properties[sa.script];
 
     hr = shape_check_typographic_feature(&context, props->scripttags, feature, glyph_count, glyphs, feature_applies);
 
-    heap_free(context.glyph_infos);
+    free(context.glyph_infos);
 
     return hr;
 }
@@ -1913,8 +1913,8 @@ static ULONG WINAPI dwritenumbersubstitution_Release(IDWriteNumberSubstitution *
 
     if (!refcount)
     {
-        heap_free(object->locale);
-        heap_free(object);
+        free(object->locale);
+        free(object);
     }
 
     return refcount;
@@ -1947,17 +1947,17 @@ HRESULT create_numbersubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD method, cons
     if (method != DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE && !IsValidLocaleName(locale))
         return E_INVALIDARG;
 
-    substitution = heap_alloc(sizeof(*substitution));
-    if (!substitution)
+    if (!(substitution = calloc(1, sizeof(*substitution))))
         return E_OUTOFMEMORY;
 
     substitution->IDWriteNumberSubstitution_iface.lpVtbl = &numbersubstitutionvtbl;
     substitution->refcount = 1;
     substitution->ignore_user_override = ignore_user_override;
     substitution->method = method;
-    substitution->locale = heap_strdupW(locale);
-    if (locale && !substitution->locale) {
-        heap_free(substitution);
+    substitution->locale = wcsdup(locale);
+    if (locale && !substitution->locale)
+    {
+        free(substitution);
         return E_OUTOFMEMORY;
     }
 
@@ -2185,7 +2185,7 @@ static HRESULT WINAPI fontfallback_MapCharacters(IDWriteFontFallback1 *iface, ID
     }
 
 done:
-    heap_free(buff);
+    free(buff);
     return hr;
 }
 
@@ -2215,8 +2215,7 @@ HRESULT create_system_fontfallback(IDWriteFactory7 *factory, IDWriteFontFallback
 
     *ret = NULL;
 
-    fallback = heap_alloc(sizeof(*fallback));
-    if (!fallback)
+    if (!(fallback = calloc(1, sizeof(*fallback))))
         return E_OUTOFMEMORY;
 
     fallback->IDWriteFontFallback1_iface.lpVtbl = &fontfallbackvtbl;
@@ -2234,7 +2233,7 @@ void release_system_fontfallback(IDWriteFontFallback1 *iface)
 {
     struct dwrite_fontfallback *fallback = impl_from_IDWriteFontFallback1(iface);
     IDWriteFontCollection1_Release(fallback->systemcollection);
-    heap_free(fallback);
+    free(fallback);
 }
 
 static ULONG WINAPI customfontfallback_AddRef(IDWriteFontFallback1 *iface)
@@ -2257,7 +2256,7 @@ static ULONG WINAPI customfontfallback_Release(IDWriteFontFallback1 *iface)
     if (!refcount)
     {
         IDWriteFactory7_Release(fallback->factory);
-        heap_free(fallback);
+        free(fallback);
     }
 
     return refcount;
@@ -2336,18 +2335,18 @@ static ULONG WINAPI fontfallbackbuilder_Release(IDWriteFontFallbackBuilder *ifac
             UINT32 j;
 
             for (j = 0; j < mapping->families_count; j++)
-                heap_free(mapping->families[j]);
-            heap_free(mapping->families);
+                free(mapping->families[j]);
+            free(mapping->families);
 
             if (mapping->collection)
                 IDWriteFontCollection_Release(mapping->collection);
-            heap_free(mapping->ranges);
-            heap_free(mapping->locale);
+            free(mapping->ranges);
+            free(mapping->locale);
         }
 
         IDWriteFactory7_Release(fallbackbuilder->factory);
-        heap_free(fallbackbuilder->mappings);
-        heap_free(fallbackbuilder);
+        free(fallbackbuilder->mappings);
+        free(fallbackbuilder);
     }
 
     return refcount;
@@ -2378,17 +2377,17 @@ static HRESULT WINAPI fontfallbackbuilder_AddMapping(IDWriteFontFallbackBuilder
 
     mapping = &fallbackbuilder->mappings[fallbackbuilder->count++];
 
-    mapping->ranges = heap_calloc(ranges_count, sizeof(*mapping->ranges));
+    mapping->ranges = calloc(ranges_count, sizeof(*mapping->ranges));
     memcpy(mapping->ranges, ranges, sizeof(*mapping->ranges) * ranges_count);
     mapping->ranges_count = ranges_count;
-    mapping->families = heap_calloc(families_count, sizeof(*mapping->families));
+    mapping->families = calloc(families_count, sizeof(*mapping->families));
     mapping->families_count = families_count;
     for (i = 0; i < families_count; i++)
-        mapping->families[i] = heap_strdupW(target_families[i]);
+        mapping->families[i] = wcsdup(target_families[i]);
     mapping->collection = collection;
     if (mapping->collection)
         IDWriteFontCollection_AddRef(mapping->collection);
-    mapping->locale = heap_strdupW(locale);
+    mapping->locale = wcsdup(locale);
     mapping->scale = scale;
 
     return S_OK;
@@ -2411,8 +2410,7 @@ static HRESULT WINAPI fontfallbackbuilder_CreateFontFallback(IDWriteFontFallback
 
     *ret = NULL;
 
-    fallback = heap_alloc(sizeof(*fallback));
-    if (!fallback)
+    if (!(fallback = calloc(1, sizeof(*fallback))))
         return E_OUTOFMEMORY;
 
     fallback->IDWriteFontFallback1_iface.lpVtbl = &customfontfallbackvtbl;
@@ -2440,8 +2438,7 @@ HRESULT create_fontfallback_builder(IDWriteFactory7 *factory, IDWriteFontFallbac
 
     *ret = NULL;
 
-    builder = heap_alloc_zero(sizeof(*builder));
-    if (!builder)
+    if (!(builder = calloc(1, sizeof(*builder))))
         return E_OUTOFMEMORY;
 
     builder->IDWriteFontFallbackBuilder_iface.lpVtbl = &fontfallbackbuildervtbl;
diff --git a/dlls/dwrite/bidi.c b/dlls/dwrite/bidi.c
index 0cfca0fd95b..cc62509b557 100644
--- a/dlls/dwrite/bidi.c
+++ b/dlls/dwrite/bidi.c
@@ -633,14 +633,16 @@ static BracketPair *bidi_compute_bracket_pairs(IsolatedRun *iso_run)
     int pair_count = 0;
     int i;
 
-    open_stack = heap_alloc(sizeof(WCHAR) * iso_run->length);
-    stack_index = heap_alloc(sizeof(int) * iso_run->length);
+    open_stack = malloc(sizeof(WCHAR) * iso_run->length);
+    stack_index = malloc(sizeof(int) * iso_run->length);
 
     for (i = 0; i < iso_run->length; i++) {
         unsigned short ubv = get_table_entry(bidi_bracket_table, iso_run->item[i].ch);
-        if (ubv) {
-            if (!out) {
-                out = heap_alloc(sizeof(BracketPair));
+        if (ubv)
+        {
+            if (!out)
+            {
+                out = malloc(sizeof(BracketPair));
                 out[0].start = -1;
             }
 
@@ -663,7 +665,7 @@ static BracketPair *bidi_compute_bracket_pairs(IsolatedRun *iso_run)
                         out[pair_count].start = stack_index[j];
                         out[pair_count].end = i;
                         pair_count++;
-                        out = heap_realloc(out, sizeof(BracketPair) * (pair_count+1));
+                        out = realloc(out, sizeof(BracketPair) * (pair_count+1));
                         out[pair_count].start = -1;
                         stack_top = j+1;
                         break;
@@ -672,15 +674,16 @@ static BracketPair *bidi_compute_bracket_pairs(IsolatedRun *iso_run)
             }
         }
     }
-    if (pair_count == 0) {
-        heap_free(out);
+    if (pair_count == 0)
+    {
+        free(out);
         out = NULL;
     }
     else if (pair_count > 1)
         qsort(out, pair_count, sizeof(BracketPair), bracketpair_compr);
 
-    heap_free(open_stack);
-    heap_free(stack_index);
+    free(open_stack);
+    free(stack_index);
     return out;
 }
 
@@ -774,7 +777,7 @@ static void bidi_resolve_neutrals(IsolatedRun *run)
             i++;
             p = &pairs[i];
         }
-        heap_free(pairs);
+        free(pairs);
     }
 
     /* N1 */
@@ -920,8 +923,7 @@ static HRESULT bidi_compute_isolating_runs_set(UINT8 baselevel, UINT8 *classes,
     HRESULT hr = S_OK;
     Run *runs;
 
-    runs = heap_calloc(count, sizeof(*runs));
-    if (!runs)
+    if (!(runs = calloc(count, sizeof(*runs))))
         return E_OUTOFMEMORY;
 
     list_init(set);
@@ -949,8 +951,8 @@ static HRESULT bidi_compute_isolating_runs_set(UINT8 baselevel, UINT8 *classes,
             int type_fence, real_end;
             int j;
 
-            current_isolated = heap_alloc(sizeof(IsolatedRun) + sizeof(RunChar)*count);
-            if (!current_isolated) {
+            if (!(current_isolated = malloc(sizeof(IsolatedRun) + sizeof(RunChar)*count)))
+            {
                 hr = E_OUTOFMEMORY;
                 break;
             }
@@ -1040,7 +1042,7 @@ search:
         i++;
     }
 
-    heap_free(runs);
+    free(runs);
     return hr;
 }
 
@@ -1053,8 +1055,7 @@ HRESULT bidi_computelevels(const WCHAR *string, UINT32 count, UINT8 baselevel, U
 
     TRACE("%s, %u\n", debugstr_wn(string, count), count);
 
-    chartype = heap_alloc(count*sizeof(*chartype));
-    if (!chartype)
+    if (!(chartype = malloc(count * sizeof(*chartype))))
         return E_OUTOFMEMORY;
 
     bidi_classify(string, chartype, count);
@@ -1081,7 +1082,7 @@ HRESULT bidi_computelevels(const WCHAR *string, UINT32 count, UINT8 baselevel, U
         if (TRACE_ON(bidi)) iso_dump_types("after neutrals", iso_run);
 
         list_remove(&iso_run->entry);
-        heap_free(iso_run);
+        free(iso_run);
     }
 
     if (TRACE_ON(bidi)) bidi_dump_types("before implicit", chartype, 0, count);
@@ -1091,6 +1092,6 @@ HRESULT bidi_computelevels(const WCHAR *string, UINT32 count, UINT8 baselevel, U
     bidi_resolve_resolved(baselevel, chartype, levels, 0, count-1);
 
 done:
-    heap_free(chartype);
+    free(chartype);
     return hr;
 }
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index 2b9651a906c..10617983b69 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -21,7 +21,6 @@
 #include "winternl.h"
 
 #include "wine/debug.h"
-#include "wine/heap.h"
 #include "wine/list.h"
 
 #define MS_GSUB_TAG DWRITE_MAKE_OPENTYPE_TAG('G','S','U','B')
@@ -34,29 +33,13 @@ static const DWRITE_MATRIX identity =
     0.0f, 0.0f
 };
 
-static inline LPWSTR heap_strdupW(const WCHAR *str)
-{
-    LPWSTR ret = NULL;
-
-    if(str) {
-        DWORD size;
-
-        size = (lstrlenW(str) + 1)*sizeof(WCHAR);
-        ret = heap_alloc(size);
-        if(ret)
-            memcpy(ret, str, size);
-    }
-
-    return ret;
-}
-
 static inline LPWSTR heap_strdupnW(const WCHAR *str, UINT32 len)
 {
     WCHAR *ret = NULL;
 
     if (len)
     {
-        ret = heap_alloc((len+1)*sizeof(WCHAR));
+        ret = malloc((len+1)*sizeof(WCHAR));
         if(ret)
         {
             memcpy(ret, str, len*sizeof(WCHAR));
@@ -97,10 +80,7 @@ static inline BOOL dwrite_array_reserve(void **elements, size_t *capacity, size_
     if (new_capacity < count)
         new_capacity = max_capacity;
 
-    if (!*elements)
-        new_elements = RtlAllocateHeap(GetProcessHeap(), 0, new_capacity * size);
-    else
-        new_elements = RtlReAllocateHeap(GetProcessHeap(), 0, *elements, new_capacity * size);
+    new_elements = realloc(*elements, new_capacity * size);
     if (!new_elements)
         return FALSE;
 
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index 20bb6b3159f..174ab7a3ded 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -420,10 +420,10 @@ static HRESULT set_cached_glyph_metrics(struct dwrite_fontface *fontface, UINT16
 {
     DWRITE_GLYPH_METRICS **block = &fontface->glyphs[glyph >> GLYPH_BLOCK_SHIFT];
 
-    if (!*block) {
+    if (!*block)
+    {
         /* start new block */
-        *block = heap_alloc_zero(sizeof(*metrics) * GLYPH_BLOCK_SIZE);
-        if (!*block)
+        if (!(*block = calloc(GLYPH_BLOCK_SIZE, sizeof(*metrics))))
             return E_OUTOFMEMORY;
     }
 
@@ -511,8 +511,8 @@ static void release_font_data(struct dwrite_font_data *data)
 
     dwrite_cmap_release(&data->cmap);
     IDWriteFontFile_Release(data->file);
-    heap_free(data->facename);
-    heap_free(data);
+    free(data->facename);
+    free(data);
 }
 
 static void release_fontfamily_data(struct dwrite_fontfamily_data *data)
@@ -524,9 +524,9 @@ static void release_fontfamily_data(struct dwrite_fontfamily_data *data)
 
     for (i = 0; i < data->count; ++i)
         release_font_data(data->fonts[i]);
-    heap_free(data->fonts);
+    free(data->fonts);
     IDWriteLocalizedStrings_Release(data->familyname);
-    heap_free(data);
+    free(data);
 }
 
 void fontface_detach_from_cache(IDWriteFontFace5 *iface)
@@ -621,7 +621,7 @@ static ULONG WINAPI dwritefontface_Release(IDWriteFontFace5 *iface)
             factory_lock(fontface->factory);
             list_remove(&fontface->cached->entry);
             factory_unlock(fontface->factory);
-            heap_free(fontface->cached);
+            free(fontface->cached);
         }
         release_scriptshaping_cache(fontface->shaping_cache);
         if (fontface->vdmx.context)
@@ -647,7 +647,7 @@ static ULONG WINAPI dwritefontface_Release(IDWriteFontFace5 *iface)
         }
 
         for (i = 0; i < ARRAY_SIZE(fontface->glyphs); i++)
-            heap_free(fontface->glyphs[i]);
+            free(fontface->glyphs[i]);
 
         font_funcs->notify_release(iface);
         font_funcs->release_font_object(fontface->font_object);
@@ -660,7 +660,7 @@ static ULONG WINAPI dwritefontface_Release(IDWriteFontFace5 *iface)
         dwrite_cmap_release(&fontface->cmap);
         IDWriteFactory7_Release(fontface->factory);
         DeleteCriticalSection(&fontface->cs);
-        heap_free(fontface);
+        free(fontface);
     }
 
     return refcount;
@@ -861,12 +861,12 @@ static HRESULT WINAPI dwritefontface_GetGlyphRunOutline(IDWriteFontFace5 *iface,
     run.isSideways = is_sideways;
     run.bidiLevel = is_rtl ? 1 : 0;
 
-    if (!(origins = heap_alloc(sizeof(*origins) * count)))
+    if (!(origins = malloc(sizeof(*origins) * count)))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = compute_glyph_origins(&run, DWRITE_MEASURING_MODE_NATURAL, baseline_origin, NULL, origins)))
     {
-        heap_free(origins);
+        free(origins);
         return hr;
     }
 
@@ -924,9 +924,9 @@ static HRESULT WINAPI dwritefontface_GetGlyphRunOutline(IDWriteFontFace5 *iface,
         }
     }
 
-    heap_free(outline.tags.values);
-    heap_free(outline.points.values);
-    heap_free(origins);
+    free(outline.tags.values);
+    free(outline.points.values);
+    free(origins);
 
     return S_OK;
 }
@@ -2011,7 +2011,7 @@ static ULONG WINAPI dwritefont_Release(IDWriteFont3 *iface)
     {
         IDWriteFontFamily2_Release(&font->family->IDWriteFontFamily2_iface);
         release_font_data(font->data);
-        heap_free(font);
+        free(font);
     }
 
     return refcount;
@@ -2321,7 +2321,7 @@ static HRESULT create_font(struct dwrite_fontfamily *family, UINT32 index, IDWri
 
     *font = NULL;
 
-    if (!(object = heap_alloc(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteFont3_iface.lpVtbl = &dwritefontvtbl;
@@ -2377,13 +2377,13 @@ static ULONG WINAPI dwritefontlist_Release(IDWriteFontList2 *iface)
 
     if (!refcount)
     {
-        UINT32 i;
+        unsigned int i;
 
         for (i = 0; i < fontlist->font_count; i++)
             release_font_data(fontlist->fonts[i]);
         IDWriteFontFamily2_Release(&fontlist->family->IDWriteFontFamily2_iface);
-        heap_free(fontlist->fonts);
-        heap_free(fontlist);
+        free(fontlist->fonts);
+        free(fontlist);
     }
 
     return refcount;
@@ -2546,7 +2546,7 @@ static ULONG WINAPI dwritefontfamily_Release(IDWriteFontFamily2 *iface)
     {
         IDWriteFontCollection3_Release(&family->collection->IDWriteFontCollection3_iface);
         release_fontfamily_data(family->data);
-        heap_free(family);
+        free(family);
     }
 
     return refcount;
@@ -2713,14 +2713,13 @@ static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily2 *ifac
 
     *ret = NULL;
 
-    fonts = heap_alloc(sizeof(*fonts));
-    if (!fonts)
+    if (!(fonts = malloc(sizeof(*fonts))))
         return E_OUTOFMEMORY;
 
     /* Allocate as many as family has, not all of them will be necessary used. */
-    fonts->fonts = heap_calloc(family->data->count, sizeof(*fonts->fonts));
-    if (!fonts->fonts) {
-        heap_free(fonts);
+    if (!(fonts->fonts = calloc(family->data->count, sizeof(*fonts->fonts))))
+    {
+        free(fonts);
         return E_OUTOFMEMORY;
     }
 
@@ -2921,8 +2920,7 @@ static HRESULT create_fontfamily(struct dwrite_fontcollection *collection, UINT3
 
     *family = NULL;
 
-    object = heap_alloc(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteFontFamily2_iface.lpVtbl = &fontfamilyvtbl;
@@ -3016,8 +3014,8 @@ static ULONG WINAPI dwritefontcollection_Release(IDWriteFontCollection3 *iface)
         factory_detach_fontcollection(collection->factory, iface);
         for (i = 0; i < collection->count; ++i)
             release_fontfamily_data(collection->family_data[i]);
-        heap_free(collection->family_data);
-        heap_free(collection);
+        free(collection->family_data);
+        free(collection);
     }
 
     return refcount;
@@ -3384,8 +3382,10 @@ static BOOL match_pattern_list(struct list *tokens, const struct name_pattern *p
         int len_part1 = wcslen(pattern->part1);
         int len_part2 = pattern->part2 ? wcslen(pattern->part2) : 0;
 
-        LIST_FOR_EACH_ENTRY(token, tokens, struct name_token, entry) {
-            if (len_part2 == 0) {
+        LIST_FOR_EACH_ENTRY(token, tokens, struct name_token, entry)
+        {
+            if (!len_part2)
+            {
                 /* simple case with single part pattern */
                 if (token->len != len_part1)
                     continue;
@@ -3394,11 +3394,12 @@ static BOOL match_pattern_list(struct list *tokens, const struct name_pattern *p
                 {
                     if (match) *match = *token;
                     list_remove(&token->entry);
-                    heap_free(token);
+                    free(token);
                     return TRUE;
                 }
             }
-            else {
+            else
+            {
                 struct name_token *next_token;
                 struct list *next_entry;
 
@@ -3418,7 +3419,7 @@ static BOOL match_pattern_list(struct list *tokens, const struct name_pattern *p
                     /* combined string match */
                     if (match) *match = *token;
                     list_remove(&token->entry);
-                    heap_free(token);
+                    free(token);
                     return TRUE;
                 }
 
@@ -3445,8 +3446,8 @@ static BOOL match_pattern_list(struct list *tokens, const struct name_pattern *p
                     }
                     list_remove(&token->entry);
                     list_remove(&next_token->entry);
-                    heap_free(next_token);
-                    heap_free(token);
+                    free(next_token);
+                    free(token);
                     return TRUE;
                 }
             }
@@ -3839,8 +3840,9 @@ static void fontname_tokenize(struct list *tokens, const WCHAR *nameW)
     list_init(tokens);
     ptr = nameW;
 
-    while (*ptr) {
-        struct name_token *token = heap_alloc(sizeof(*token));
+    while (*ptr)
+    {
+        struct name_token *token = malloc(sizeof(*token));
         token->ptr = ptr;
         token->len = 0;
         token->fulllen = 0;
@@ -3874,7 +3876,7 @@ static void fontname_tokens_to_str(struct list *tokens, WCHAR *nameW)
         memcpy(nameW, token->ptr, len * sizeof(WCHAR));
         nameW += len;
 
-        heap_free(token);
+        free(token);
     }
     *nameW = 0;
 }
@@ -4052,8 +4054,7 @@ static HRESULT init_font_data(const struct fontface_desc *desc, struct dwrite_fo
 
     *ret = NULL;
 
-    data = heap_alloc_zero(sizeof(*data));
-    if (!data)
+    if (!(data = calloc(1, sizeof(*data))))
         return E_OUTOFMEMORY;
 
     data->refcount = 1;
@@ -4112,8 +4113,7 @@ static HRESULT init_font_data_from_font(const struct dwrite_font_data *src, DWRI
 
     *ret = NULL;
 
-    data = heap_alloc_zero(sizeof(*data));
-    if (!data)
+    if (!(data = calloc(1, sizeof(*data))))
         return E_OUTOFMEMORY;
 
     *data = *src;
@@ -4141,8 +4141,7 @@ static HRESULT init_fontfamily_data(IDWriteLocalizedStrings *familyname, struct
 {
     struct dwrite_fontfamily_data *data;
 
-    data = heap_alloc_zero(sizeof(*data));
-    if (!data)
+    if (!(data = calloc(1, sizeof(*data))))
         return E_OUTOFMEMORY;
 
     data->refcount = 1;
@@ -4349,8 +4348,8 @@ static void fontcollection_add_replacements(struct dwrite_fontcollection *collec
     }
 
     max_namelen++; /* returned value doesn't include room for '\0' */
-    name = heap_alloc(max_namelen * sizeof(WCHAR));
-    data = heap_alloc(max_datalen);
+    name = malloc(max_namelen * sizeof(WCHAR));
+    data = malloc(max_datalen);
 
     datalen = max_datalen;
     namelen = max_namelen;
@@ -4374,8 +4373,8 @@ static void fontcollection_add_replacements(struct dwrite_fontcollection *collec
         namelen = max_namelen;
     }
 
-    heap_free(data);
-    heap_free(name);
+    free(data);
+    free(name);
     RegCloseKey(hkey);
 }
 
@@ -4395,12 +4394,13 @@ HRESULT create_font_collection(IDWriteFactory7 *factory, IDWriteFontFileEnumerat
 
     *ret = NULL;
 
-    collection = heap_alloc(sizeof(struct dwrite_fontcollection));
-    if (!collection) return E_OUTOFMEMORY;
+    if (!(collection = calloc(1, sizeof(*collection))))
+        return E_OUTOFMEMORY;
 
     hr = init_font_collection(collection, is_system);
-    if (FAILED(hr)) {
-        heap_free(collection);
+    if (FAILED(hr))
+    {
+        free(collection);
         return hr;
     }
 
@@ -4453,7 +4453,7 @@ HRESULT create_font_collection(IDWriteFactory7 *factory, IDWriteFontFileEnumerat
         }
 
         /* add to scanned list */
-        fileenum = heap_alloc(sizeof(*fileenum));
+        fileenum = malloc(sizeof(*fileenum));
         fileenum->file = file;
         list_add_tail(&scannedfiles, &fileenum->entry);
 
@@ -4520,10 +4520,11 @@ HRESULT create_font_collection(IDWriteFactory7 *factory, IDWriteFontFileEnumerat
         IDWriteFontFileStream_Release(stream);
     }
 
-    LIST_FOR_EACH_ENTRY_SAFE(fileenum, fileenum2, &scannedfiles, struct fontfile_enum, entry) {
+    LIST_FOR_EACH_ENTRY_SAFE(fileenum, fileenum2, &scannedfiles, struct fontfile_enum, entry)
+    {
         IDWriteFontFile_Release(fileenum->file);
         list_remove(&fileenum->entry);
-        heap_free(fileenum);
+        free(fileenum);
     }
 
     for (i = 0; i < collection->count; ++i)
@@ -4589,8 +4590,8 @@ static ULONG WINAPI systemfontfileenumerator_Release(IDWriteFontFileEnumerator *
     {
         IDWriteFactory7_Release(enumerator->factory);
         RegCloseKey(enumerator->hkey);
-        heap_free(enumerator->filename);
-        heap_free(enumerator);
+        free(enumerator->filename);
+        free(enumerator);
     }
 
     return refcount;
@@ -4650,16 +4651,17 @@ static HRESULT WINAPI systemfontfileenumerator_MoveNext(IDWriteFontFileEnumerato
                               NULL, &type, (BYTE *)enumerator->filename, &data_size);
             if (r == ERROR_MORE_DATA) {
                 if (name_count >= max_name_count) {
-                    if (name != name_buf) heap_free(name);
+                    if (name != name_buf) free(name);
                     max_name_count *= 2;
-                    name = heap_alloc(max_name_count * sizeof(*name));
+                    name = malloc(max_name_count * sizeof(*name));
                     if (!name) return E_OUTOFMEMORY;
                 }
-                if (data_size > enumerator->filename_size - sizeof(*enumerator->filename)) {
-                    heap_free(enumerator->filename);
+                if (data_size > enumerator->filename_size - sizeof(*enumerator->filename))
+                {
+                    free(enumerator->filename);
                     enumerator->filename_size = max(data_size + sizeof(*enumerator->filename), enumerator->filename_size * 2);
-                    enumerator->filename = heap_alloc(enumerator->filename_size);
-                    if (!enumerator->filename) {
+                    if (!(enumerator->filename = malloc(enumerator->filename_size)))
+                    {
                         hr = E_OUTOFMEMORY;
                         goto err;
                     }
@@ -4681,7 +4683,7 @@ static HRESULT WINAPI systemfontfileenumerator_MoveNext(IDWriteFontFileEnumerato
     TRACE("index = %d, current = %d\n", enumerator->index, *current);
 
 err:
-    if (name != name_buf) heap_free(name);
+    if (name != name_buf) free(name);
     return hr;
 }
 
@@ -4700,8 +4702,7 @@ static HRESULT create_system_fontfile_enumerator(IDWriteFactory7 *factory, IDWri
 
     *ret = NULL;
 
-    enumerator = heap_alloc(sizeof(*enumerator));
-    if (!enumerator)
+    if (!(enumerator = calloc(1, sizeof(*enumerator))))
         return E_OUTOFMEMORY;
 
     enumerator->IDWriteFontFileEnumerator_iface.lpVtbl = &systemfontfileenumeratorvtbl;
@@ -4709,9 +4710,10 @@ static HRESULT create_system_fontfile_enumerator(IDWriteFactory7 *factory, IDWri
     enumerator->factory = factory;
     enumerator->index = -1;
     enumerator->filename_size = MAX_PATH * sizeof(*enumerator->filename);
-    enumerator->filename = heap_alloc(enumerator->filename_size);
-    if (!enumerator->filename) {
-        heap_free(enumerator);
+    enumerator->filename = malloc(enumerator->filename_size);
+    if (!enumerator->filename)
+    {
+        free(enumerator);
         return E_OUTOFMEMORY;
     }
 
@@ -4722,8 +4724,8 @@ static HRESULT create_system_fontfile_enumerator(IDWriteFactory7 *factory, IDWri
     {
         ERR("failed to open fonts list key\n");
         IDWriteFactory7_Release(factory);
-        heap_free(enumerator->filename);
-        heap_free(enumerator);
+        free(enumerator->filename);
+        free(enumerator);
         return E_FAIL;
     }
 
@@ -4847,12 +4849,13 @@ HRESULT get_eudc_fontcollection(IDWriteFactory7 *factory, IDWriteFontCollection3
 
     *ret = NULL;
 
-    collection = heap_alloc(sizeof(struct dwrite_fontcollection));
-    if (!collection) return E_OUTOFMEMORY;
+    if (!(collection = calloc(1, sizeof(*collection))))
+        return E_OUTOFMEMORY;
 
     hr = init_font_collection(collection, FALSE);
-    if (FAILED(hr)) {
-        heap_free(collection);
+    if (FAILED(hr))
+    {
+        free(collection);
         return hr;
     }
 
@@ -4943,8 +4946,8 @@ static ULONG WINAPI dwritefontfile_Release(IDWriteFontFile *iface)
         IDWriteFontFileLoader_Release(file->loader);
         if (file->stream)
             IDWriteFontFileStream_Release(file->stream);
-        heap_free(file->reference_key);
-        heap_free(file);
+        free(file->reference_key);
+        free(file);
     }
 
     return refcount;
@@ -5018,11 +5021,12 @@ HRESULT create_font_file(IDWriteFontFileLoader *loader, const void *reference_ke
 
     *ret = NULL;
 
-    file = heap_alloc(sizeof(*file));
-    key = heap_alloc(key_size);
-    if (!file || !key) {
-        heap_free(file);
-        heap_free(key);
+    file = calloc(1, sizeof(*file));
+    key = malloc(key_size);
+    if (!file || !key)
+    {
+        free(file);
+        free(key);
         return E_OUTOFMEMORY;
     }
 
@@ -5076,8 +5080,7 @@ HRESULT create_fontface(const struct fontface_desc *desc, struct list *cached_li
 
     *ret = NULL;
 
-    fontface = heap_alloc_zero(sizeof(struct dwrite_fontface));
-    if (!fontface)
+    if (!(fontface = calloc(1, sizeof(*fontface))))
         return E_OUTOFMEMORY;
 
     fontface->IDWriteFontFace5_iface.lpVtbl = &dwritefontfacevtbl;
@@ -5252,8 +5255,8 @@ static void release_inmemory_stream(struct dwrite_inmemory_stream_data *stream)
         if (stream->owner)
             IUnknown_Release(stream->owner);
         else
-            heap_free(stream->data);
-        heap_free(stream);
+            free(stream->data);
+        free(stream);
     }
 }
 
@@ -5295,8 +5298,8 @@ static ULONG WINAPI localfontfilestream_AddRef(IDWriteFontFileStream *iface)
 static inline void release_cached_stream(struct local_cached_stream *stream)
 {
     list_remove(&stream->entry);
-    heap_free(stream->key);
-    heap_free(stream);
+    free(stream->key);
+    free(stream);
 }
 
 static ULONG WINAPI localfontfilestream_Release(IDWriteFontFileStream *iface)
@@ -5314,7 +5317,7 @@ static ULONG WINAPI localfontfilestream_Release(IDWriteFontFileStream *iface)
         release_cached_stream(stream->entry);
         LeaveCriticalSection(&local_fontfile_loader.cs);
 
-        heap_free(stream);
+        free(stream);
     }
 
     return refcount;
@@ -5387,7 +5390,7 @@ static HRESULT create_localfontfilestream(const void *file_ptr, UINT64 size, str
 
     *ret = NULL;
 
-    if (!(object = heap_alloc(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteFontFileStream_iface.lpVtbl = &localfontfilestreamvtbl;
@@ -5473,27 +5476,27 @@ static HRESULT create_local_cached_stream(const void *key, UINT32 key_size, stru
         return E_FAIL;
     }
 
-    stream = heap_alloc(sizeof(*stream));
-    if (!stream) {
+    if (!(stream = malloc(sizeof(*stream))))
+    {
         UnmapViewOfFile(file_ptr);
         return E_OUTOFMEMORY;
     }
 
-    stream->key = heap_alloc(key_size);
-    if (!stream->key) {
+    if (!(stream->key = malloc(key_size)))
+    {
         UnmapViewOfFile(file_ptr);
-        heap_free(stream);
+        free(stream);
         return E_OUTOFMEMORY;
     }
 
     stream->key_size = key_size;
     memcpy(stream->key, key, key_size);
 
-    hr = create_localfontfilestream(file_ptr, size.QuadPart, stream, &filestream);
-    if (FAILED(hr)) {
+    if (FAILED(hr = create_localfontfilestream(file_ptr, size.QuadPart, stream, &filestream)))
+    {
         UnmapViewOfFile(file_ptr);
-        heap_free(stream->key);
-        heap_free(stream);
+        free(stream->key);
+        free(stream);
         return hr;
     }
 
@@ -5608,8 +5611,7 @@ HRESULT get_local_refkey(const WCHAR *path, const FILETIME *writetime, void **ke
     *size = FIELD_OFFSET(struct local_refkey, name) + (wcslen(path)+1)*sizeof(WCHAR);
     *key = NULL;
 
-    refkey = heap_alloc(*size);
-    if (!refkey)
+    if (!(refkey = malloc(*size)))
         return E_OUTOFMEMORY;
 
     if (writetime)
@@ -5668,10 +5670,10 @@ static ULONG WINAPI glyphrunanalysis_Release(IDWriteGlyphRunAnalysis *iface)
     {
         if (analysis->run.fontFace)
             IDWriteFontFace_Release(analysis->run.fontFace);
-        heap_free(analysis->glyphs);
-        heap_free(analysis->origins);
-        heap_free(analysis->bitmap);
-        heap_free(analysis);
+        free(analysis->glyphs);
+        free(analysis->origins);
+        free(analysis->bitmap);
+        free(analysis);
     }
 
     return refcount;
@@ -5795,7 +5797,8 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis)
     size = (analysis->bounds.right - analysis->bounds.left)*(analysis->bounds.bottom - analysis->bounds.top);
     if (analysis->texture_type == DWRITE_TEXTURE_CLEARTYPE_3x1)
         size *= 3;
-    if (!(analysis->bitmap = heap_alloc_zero(size))) {
+    if (!(analysis->bitmap = calloc(1, size)))
+    {
         WARN("Failed to allocate run bitmap, %s, type %s.\n", wine_dbgstr_rect(&analysis->bounds),
                 analysis->texture_type == DWRITE_TEXTURE_CLEARTYPE_3x1 ? "3x1" : "1x1");
         IDWriteFontFace4_Release(fontface);
@@ -5812,7 +5815,8 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis)
     glyph_bitmap.aliased = analysis->rendering_mode == DWRITE_RENDERING_MODE1_ALIASED;
     if (analysis->flags & RUNANALYSIS_USE_TRANSFORM)
         glyph_bitmap.m = &analysis->m;
-    if (!(glyph_bitmap.buf = heap_alloc(analysis->max_glyph_bitmap_size))) {
+    if (!(glyph_bitmap.buf = malloc(analysis->max_glyph_bitmap_size)))
+    {
         IDWriteFontFace4_Release(fontface);
         return E_OUTOFMEMORY;
     }
@@ -5882,15 +5886,15 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis)
             }
         }
     }
-    heap_free(glyph_bitmap.buf);
+    free(glyph_bitmap.buf);
 
     IDWriteFontFace4_Release(fontface);
 
     analysis->flags |= RUNANALYSIS_BITMAP_READY;
 
     /* we don't need this anymore */
-    heap_free(analysis->glyphs);
-    heap_free(analysis->origins);
+    free(analysis->glyphs);
+    free(analysis->origins);
     IDWriteFontFace_Release(analysis->run.fontFace);
 
     analysis->glyphs = NULL;
@@ -6060,8 +6064,7 @@ HRESULT create_glyphrunanalysis(const struct glyphrunanalysis_desc *desc, IDWrit
     if ((UINT32)desc->measuring_mode > DWRITE_MEASURING_MODE_GDI_NATURAL)
         return E_INVALIDARG;
 
-    analysis = heap_alloc_zero(sizeof(*analysis));
-    if (!analysis)
+    if (!(analysis = calloc(1, sizeof(*analysis))))
         return E_OUTOFMEMORY;
 
     analysis->IDWriteGlyphRunAnalysis_iface.lpVtbl = &glyphrunanalysisvtbl;
@@ -6076,12 +6079,13 @@ HRESULT create_glyphrunanalysis(const struct glyphrunanalysis_desc *desc, IDWrit
 
     analysis->run = *desc->run;
     IDWriteFontFace_AddRef(analysis->run.fontFace);
-    analysis->glyphs = heap_calloc(desc->run->glyphCount, sizeof(*analysis->glyphs));
-    analysis->origins = heap_calloc(desc->run->glyphCount, sizeof(*analysis->origins));
+    analysis->glyphs = calloc(desc->run->glyphCount, sizeof(*analysis->glyphs));
+    analysis->origins = calloc(desc->run->glyphCount, sizeof(*analysis->origins));
 
-    if (!analysis->glyphs || !analysis->origins) {
-        heap_free(analysis->glyphs);
-        heap_free(analysis->origins);
+    if (!analysis->glyphs || !analysis->origins)
+    {
+        free(analysis->glyphs);
+        free(analysis->origins);
 
         analysis->glyphs = NULL;
         analysis->origins = NULL;
@@ -6149,16 +6153,16 @@ static ULONG WINAPI colorglyphenum_Release(IDWriteColorGlyphRunEnumerator1 *ifac
 
     if (!refcount)
     {
-        heap_free(glyphenum->advances);
-        heap_free(glyphenum->color_advances);
-        heap_free(glyphenum->offsets);
-        heap_free(glyphenum->color_offsets);
-        heap_free(glyphenum->glyphindices);
-        heap_free(glyphenum->glyphs);
+        free(glyphenum->advances);
+        free(glyphenum->color_advances);
+        free(glyphenum->offsets);
+        free(glyphenum->color_offsets);
+        free(glyphenum->glyphindices);
+        free(glyphenum->glyphs);
         if (glyphenum->colr.context)
             IDWriteFontFace5_ReleaseFontTable(glyphenum->fontface, glyphenum->colr.context);
         IDWriteFontFace5_Release(glyphenum->fontface);
-        heap_free(glyphenum);
+        free(glyphenum);
     }
 
     return refcount;
@@ -6349,8 +6353,7 @@ HRESULT create_colorglyphenum(float originX, float originY, const DWRITE_GLYPH_R
     if (!colorfont)
         return DWRITE_E_NOCOLOR;
 
-    colorglyphenum = heap_alloc_zero(sizeof(*colorglyphenum));
-    if (!colorglyphenum)
+    if (!(colorglyphenum = calloc(1, sizeof(*colorglyphenum))))
         return E_OUTOFMEMORY;
 
     colorglyphenum->IDWriteColorGlyphRunEnumerator1_iface.lpVtbl = &colorglyphenumvtbl;
@@ -6371,7 +6374,7 @@ HRESULT create_colorglyphenum(float originX, float originY, const DWRITE_GLYPH_R
     colorglyphenum->current_layer = 0;
     colorglyphenum->max_layer_num = 0;
 
-    colorglyphenum->glyphs = heap_alloc_zero(run->glyphCount * sizeof(*colorglyphenum->glyphs));
+    colorglyphenum->glyphs = calloc(run->glyphCount, sizeof(*colorglyphenum->glyphs));
 
     has_colored_glyph = FALSE;
     colorglyphenum->has_regular_glyphs = FALSE;
@@ -6391,12 +6394,12 @@ HRESULT create_colorglyphenum(float originX, float originY, const DWRITE_GLYPH_R
         return DWRITE_E_NOCOLOR;
     }
 
-    colorglyphenum->advances = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->advances));
-    colorglyphenum->color_advances = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->color_advances));
-    colorglyphenum->glyphindices = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->glyphindices));
+    colorglyphenum->advances = calloc(run->glyphCount, sizeof(*colorglyphenum->advances));
+    colorglyphenum->color_advances = calloc(run->glyphCount, sizeof(*colorglyphenum->color_advances));
+    colorglyphenum->glyphindices = calloc(run->glyphCount, sizeof(*colorglyphenum->glyphindices));
     if (run->glyphOffsets) {
-        colorglyphenum->offsets = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->offsets));
-        colorglyphenum->color_offsets = heap_calloc(run->glyphCount, sizeof(*colorglyphenum->color_offsets));
+        colorglyphenum->offsets = calloc(run->glyphCount, sizeof(*colorglyphenum->offsets));
+        colorglyphenum->color_offsets = calloc(run->glyphCount, sizeof(*colorglyphenum->color_offsets));
         memcpy(colorglyphenum->offsets, run->glyphOffsets, run->glyphCount * sizeof(*run->glyphOffsets));
     }
 
@@ -6465,8 +6468,8 @@ static ULONG WINAPI fontfacereference_Release(IDWriteFontFaceReference1 *iface)
     {
         IDWriteFontFile_Release(reference->file);
         IDWriteFactory7_Release(reference->factory);
-        heap_free(reference->axis_values);
-        heap_free(reference);
+        free(reference->axis_values);
+        free(reference);
     }
 
     return refcount;
@@ -6707,8 +6710,7 @@ HRESULT create_fontfacereference(IDWriteFactory7 *factory, IDWriteFontFile *file
     if (!is_simulation_valid(simulations))
         return E_INVALIDARG;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteFontFaceReference1_iface.lpVtbl = &fontfacereferencevtbl;
@@ -6722,7 +6724,7 @@ HRESULT create_fontfacereference(IDWriteFactory7 *factory, IDWriteFontFile *file
     object->simulations = simulations;
     if (axis_values_count)
     {
-        if (!(object->axis_values = heap_alloc(axis_values_count * sizeof(*axis_values))))
+        if (!(object->axis_values = malloc(axis_values_count * sizeof(*axis_values))))
         {
             IDWriteFontFaceReference1_Release(&object->IDWriteFontFaceReference1_iface);
             return E_OUTOFMEMORY;
@@ -6772,7 +6774,7 @@ static ULONG WINAPI inmemoryfilestream_Release(IDWriteFontFileStream *iface)
     if (!refcount)
     {
         release_inmemory_stream(stream->data);
-        heap_free(stream);
+        free(stream);
     }
 
     return refcount;
@@ -6875,8 +6877,8 @@ static ULONG WINAPI inmemoryfontfileloader_Release(IDWriteInMemoryFontFileLoader
     {
         for (i = 0; i < loader->count; ++i)
             release_inmemory_stream(loader->streams[i]);
-        heap_free(loader->streams);
-        heap_free(loader);
+        free(loader->streams);
+        free(loader);
     }
 
     return refcount;
@@ -6901,7 +6903,7 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateStreamFromKey(IDWriteInMemory
     if (index >= loader->count)
         return E_INVALIDARG;
 
-    if (!(stream = heap_alloc(sizeof(*stream))))
+    if (!(stream = malloc(sizeof(*stream))))
         return E_OUTOFMEMORY;
 
     stream->IDWriteFontFileStream_iface.lpVtbl = &inmemoryfilestreamvtbl;
@@ -6928,7 +6930,7 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW
     if (!dwrite_array_reserve((void **)&loader->streams, &loader->size, loader->count + 1, sizeof(*loader->streams)))
         return E_OUTOFMEMORY;
 
-    if (!(stream = heap_alloc(sizeof(*stream))))
+    if (!(stream = malloc(sizeof(*stream))))
         return E_OUTOFMEMORY;
 
     stream->refcount = 1;
@@ -6939,8 +6941,9 @@ static HRESULT WINAPI inmemoryfontfileloader_CreateInMemoryFontFileReference(IDW
         stream->data = (void *)data;
     }
     else {
-        if (!(stream->data = heap_alloc(data_size))) {
-            heap_free(stream);
+        if (!(stream->data = malloc(data_size)))
+        {
+            free(stream);
             return E_OUTOFMEMORY;
         }
         memcpy(stream->data, data, data_size);
@@ -6978,8 +6981,7 @@ HRESULT create_inmemory_fileloader(IDWriteInMemoryFontFileLoader **ret)
 
     *ret = NULL;
 
-    loader = heap_alloc_zero(sizeof(*loader));
-    if (!loader)
+    if (!(loader = calloc(1, sizeof(*loader))))
         return E_OUTOFMEMORY;
 
     loader->IDWriteInMemoryFontFileLoader_iface.lpVtbl = &inmemoryfontfileloadervtbl;
@@ -7028,7 +7030,7 @@ static ULONG WINAPI dwritefontresource_Release(IDWriteFontResource *iface)
     {
         IDWriteFactory7_Release(resource->factory);
         IDWriteFontFile_Release(resource->file);
-        heap_free(resource);
+        free(resource);
     }
 
     return refcount;
@@ -7175,8 +7177,7 @@ HRESULT create_font_resource(IDWriteFactory7 *factory, IDWriteFontFile *file, UI
 
     *ret = NULL;
 
-    resource = heap_alloc_zero(sizeof(*resource));
-    if (!resource)
+    if (!(resource = calloc(1, sizeof(*resource))))
         return E_OUTOFMEMORY;
 
     resource->IDWriteFontResource_iface.lpVtbl = &fontresourcevtbl;
@@ -7235,7 +7236,7 @@ static void release_fontset_entry(struct dwrite_fontset_entry *entry)
         if (entry->props[i] && entry->props[i] != MISSING_SET_PROP)
             IDWriteLocalizedStrings_Release(entry->props[i]);
     }
-    heap_free(entry);
+    free(entry);
 }
 
 static struct dwrite_fontset_entry * addref_fontset_entry(struct dwrite_fontset_entry *entry)
@@ -7306,8 +7307,8 @@ static ULONG WINAPI dwritefontset_Release(IDWriteFontSet3 *iface)
         IDWriteFactory7_Release(set->factory);
         for (i = 0; i < set->count; ++i)
             release_fontset_entry(set->entries[i]);
-        heap_free(set->entries);
-        heap_free(set);
+        free(set->entries);
+        free(set);
     }
 
     return refcount;
@@ -7461,12 +7462,12 @@ static HRESULT WINAPI dwritefontset_GetMatchingFonts(IDWriteFontSet3 *iface, DWR
     if (!props && count)
         return E_INVALIDARG;
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
-    if (!(entries = heap_calloc(set->count, sizeof(*entries))))
+    if (!(entries = calloc(set->count, sizeof(*entries))))
     {
-        heap_free(object);
+        free(object);
         return E_OUTOFMEMORY;
     }
 
@@ -7480,7 +7481,7 @@ static HRESULT WINAPI dwritefontset_GetMatchingFonts(IDWriteFontSet3 *iface, DWR
 
     if (!matched_count)
     {
-        heap_free(entries);
+        free(entries);
         entries = NULL;
     }
 
@@ -7667,7 +7668,7 @@ static HRESULT fontset_create_entry(IDWriteFontFile *file, DWRITE_FONT_FACE_TYPE
 {
     struct dwrite_fontset_entry *entry;
 
-    if (!(entry = heap_alloc_zero(sizeof(*entry))))
+    if (!(entry = calloc(1, sizeof(*entry))))
         return E_OUTOFMEMORY;
 
     entry->refcount = 1;
@@ -7700,12 +7701,12 @@ static HRESULT fontset_create_from_font_data(IDWriteFactory7 *factory, struct dw
     struct dwrite_fontset *object;
     unsigned int i;
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (count)
     {
-        entries = heap_calloc(count, sizeof(*entries));
+        entries = calloc(count, sizeof(*entries));
 
         /* FIXME: set available properties too */
 
@@ -7729,12 +7730,12 @@ static HRESULT fontset_builder_create_fontset(IDWriteFactory7 *factory, struct d
     struct dwrite_fontset *object;
     unsigned int i;
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (count)
     {
-        entries = heap_calloc(count, sizeof(*entries));
+        entries = calloc(count, sizeof(*entries));
 
         for (i = 0; i < count; ++i)
             entries[i] = addref_fontset_entry(src_entries[i]);
@@ -7789,8 +7790,8 @@ static ULONG WINAPI dwritefontsetbuilder_Release(IDWriteFontSetBuilder2 *iface)
         IDWriteFactory7_Release(builder->factory);
         for (i = 0; i < builder->count; ++i)
             release_fontset_entry(builder->entries[i]);
-        heap_free(builder->entries);
-        heap_free(builder);
+        free(builder->entries);
+        free(builder);
     }
 
     return refcount;
@@ -7952,7 +7953,7 @@ HRESULT create_fontset_builder(IDWriteFactory7 *factory, IDWriteFontSetBuilder2
 
     *ret = NULL;
 
-    if (!(builder = heap_alloc_zero(sizeof(*builder))))
+    if (!(builder = calloc(1, sizeof(*builder))))
         return E_OUTOFMEMORY;
 
     builder->IDWriteFontSetBuilder2_iface.lpVtbl = &fontsetbuildervtbl;
@@ -8005,7 +8006,7 @@ static int CDECL get_font_data_cb(void *key, const void **data_ptr, UINT64 *data
         return 1;
     }
 
-    if (!(context = heap_alloc(sizeof(*context))))
+    if (!(context = malloc(sizeof(*context))))
     {
         IDWriteFontFileStream_Release(stream);
         return 1;
@@ -8025,7 +8026,7 @@ static void CDECL release_font_data_cb(struct font_data_context *context)
     if (!context) return;
     IDWriteFontFileStream_ReleaseFileFragment(context->stream, context->context);
     IDWriteFontFileStream_Release(context->stream);
-    heap_free(context);
+    free(context);
 }
 
 struct font_callback_funcs callback_funcs =
diff --git a/dlls/dwrite/gdiinterop.c b/dlls/dwrite/gdiinterop.c
index 8df3f9f97ca..e8b4a747e29 100644
--- a/dlls/dwrite/gdiinterop.c
+++ b/dlls/dwrite/gdiinterop.c
@@ -267,7 +267,7 @@ static ULONG WINAPI rendertarget_Release(IDWriteBitmapRenderTarget1 *iface)
     {
         IDWriteFactory7_Release(target->factory);
         DeleteDC(target->hdc);
-        heap_free(target);
+        free(target);
     }
 
     return refcount;
@@ -460,8 +460,8 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac
         color = colorref_to_pixel_888(color);
         if (texturetype == DWRITE_TEXTURE_CLEARTYPE_3x1)
             size *= 3;
-        bitmap = heap_alloc_zero(size);
-        if (!bitmap) {
+        if (!(bitmap = calloc(1, size)))
+        {
             IDWriteGlyphRunAnalysis_Release(analysis);
             return E_OUTOFMEMORY;
         }
@@ -477,7 +477,7 @@ static HRESULT WINAPI rendertarget_DrawGlyphRun(IDWriteBitmapRenderTarget1 *ifac
             if (bbox_ret) *bbox_ret = target_rect;
         }
 
-        heap_free(bitmap);
+        free(bitmap);
     }
 
     IDWriteGlyphRunAnalysis_Release(analysis);
@@ -605,8 +605,8 @@ static HRESULT create_rendertarget(IDWriteFactory7 *factory, HDC hdc, UINT32 wid
 
     *ret = NULL;
 
-    target = heap_alloc(sizeof(struct rendertarget));
-    if (!target) return E_OUTOFMEMORY;
+    if (!(target = malloc(sizeof(*target))))
+        return E_OUTOFMEMORY;
 
     target->IDWriteBitmapRenderTarget1_iface.lpVtbl = &rendertargetvtbl;
     target->ID2D1SimplifiedGeometrySink_iface.lpVtbl = &rendertargetsinkvtbl;
@@ -671,7 +671,7 @@ static ULONG WINAPI gdiinterop_Release(IDWriteGdiInterop1 *iface)
     {
         IDWriteFactory7_UnregisterFontFileLoader(interop->factory, &interop->IDWriteFontFileLoader_iface);
         factory_detach_gdiinterop(interop->factory, iface);
-        heap_free(interop);
+        free(interop);
     }
 
     return refcount;
@@ -795,12 +795,12 @@ static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop1 *iface
         return E_FAIL;
     }
 
-    fileinfo = heap_alloc(needed);
-    if (!fileinfo)
+    if (!(fileinfo = malloc(needed)))
         return E_OUTOFMEMORY;
 
-    if (!GetFontFileInfo(info.instance_id, 0, fileinfo, needed, &needed)) {
-        heap_free(fileinfo);
+    if (!GetFontFileInfo(info.instance_id, 0, fileinfo, needed, &needed))
+    {
+        free(fileinfo);
         return E_FAIL;
     }
 
@@ -810,7 +810,7 @@ static HRESULT WINAPI gdiinterop_CreateFontFaceFromHdc(IDWriteGdiInterop1 *iface
         hr = IDWriteFactory7_CreateCustomFontFileReference(interop->factory, &info.instance_id,
                 sizeof(info.instance_id), &interop->IDWriteFontFileLoader_iface, &file);
 
-    heap_free(fileinfo);
+    free(fileinfo);
     if (FAILED(hr))
         return hr;
 
@@ -962,7 +962,7 @@ static ULONG WINAPI memresourcestream_Release(IDWriteFontFileStream *iface)
     TRACE("%p, refcount %d.\n", iface, refcount);
 
     if (!refcount)
-        heap_free(stream);
+        free(stream);
 
     return refcount;
 }
@@ -986,7 +986,7 @@ static HRESULT WINAPI memresourcestream_ReadFileFragment(IDWriteFontFileStream *
     if ((offset >= fileinfo.size.QuadPart - 1) || (fragment_size > fileinfo.size.QuadPart - offset))
         return E_INVALIDARG;
 
-    if (!(fragment = heap_alloc(fragment_size)))
+    if (!(fragment = malloc(fragment_size)))
         return E_OUTOFMEMORY;
 
     if (!GetFontFileData(stream->key, 0, offset, fragment, fragment_size))
@@ -1000,7 +1000,7 @@ static void WINAPI memresourcestream_ReleaseFileFragment(IDWriteFontFileStream *
 {
     TRACE("%p, %p.\n", iface, fragment_context);
 
-    heap_free(fragment_context);
+    free(fragment_context);
 }
 
 static HRESULT WINAPI memresourcestream_GetFileSize(IDWriteFontFileStream *iface, UINT64 *size)
@@ -1073,7 +1073,7 @@ static HRESULT WINAPI memresourceloader_CreateStreamFromKey(IDWriteFontFileLoade
     if (!key || key_size != sizeof(DWORD))
         return E_INVALIDARG;
 
-    if (!(stream = heap_alloc(sizeof(*stream))))
+    if (!(stream = malloc(sizeof(*stream))))
         return E_OUTOFMEMORY;
 
     stream->IDWriteFontFileStream_iface.lpVtbl = &memresourcestreamvtbl;
@@ -1099,7 +1099,7 @@ HRESULT create_gdiinterop(IDWriteFactory7 *factory, IDWriteGdiInterop1 **ret)
 
     *ret = NULL;
 
-    if (!(interop = heap_alloc(sizeof(*interop))))
+    if (!(interop = malloc(sizeof(*interop))))
         return E_OUTOFMEMORY;
 
     interop->IDWriteGdiInterop1_iface.lpVtbl = &gdiinteropvtbl;
diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c
index 26744e1b303..b2e71e7f436 100644
--- a/dlls/dwrite/layout.c
+++ b/dlls/dwrite/layout.c
@@ -329,9 +329,9 @@ static void release_format_data(struct dwrite_textformat_data *data)
     if (data->collection) IDWriteFontCollection_Release(data->collection);
     if (data->fallback) IDWriteFontFallback_Release(data->fallback);
     if (data->trimmingsign) IDWriteInlineObject_Release(data->trimmingsign);
-    heap_free(data->family_name);
-    heap_free(data->locale);
-    heap_free(data->axis_values);
+    free(data->family_name);
+    free(data->locale);
+    free(data->axis_values);
 }
 
 static inline struct dwrite_textlayout *impl_from_IDWriteTextLayout4(IDWriteTextLayout4 *iface)
@@ -472,13 +472,13 @@ static inline HRESULT format_set_linespacing(struct dwrite_textformat_data *form
 static HRESULT format_set_font_axisvalues(struct dwrite_textformat_data *format,
         DWRITE_FONT_AXIS_VALUE const *axis_values, unsigned int num_values)
 {
-    heap_free(format->axis_values);
+    free(format->axis_values);
     format->axis_values = NULL;
     format->axis_values_count = 0;
 
     if (num_values)
     {
-        if (!(format->axis_values = heap_calloc(num_values, sizeof(*axis_values))))
+        if (!(format->axis_values = calloc(num_values, sizeof(*axis_values))))
             return E_OUTOFMEMORY;
         memcpy(format->axis_values, axis_values, num_values * sizeof(*axis_values));
         format->axis_values_count = num_values;
@@ -552,7 +552,7 @@ static BOOL is_run_rtl(const struct layout_effective_run *run)
 static HRESULT alloc_layout_run(enum layout_run_kind kind, unsigned int start_position,
         struct layout_run **run)
 {
-    if (!(*run = heap_alloc_zero(sizeof(**run))))
+    if (!(*run = calloc(1, sizeof(**run))))
         return E_OUTOFMEMORY;
 
     (*run)->kind = kind;
@@ -564,17 +564,19 @@ static HRESULT alloc_layout_run(enum layout_run_kind kind, unsigned int start_po
 static void free_layout_runs(struct dwrite_textlayout *layout)
 {
     struct layout_run *cur, *cur2;
-    LIST_FOR_EACH_ENTRY_SAFE(cur, cur2, &layout->runs, struct layout_run, entry) {
+    LIST_FOR_EACH_ENTRY_SAFE(cur, cur2, &layout->runs, struct layout_run, entry)
+    {
         list_remove(&cur->entry);
-        if (cur->kind == LAYOUT_RUN_REGULAR) {
+        if (cur->kind == LAYOUT_RUN_REGULAR)
+        {
             if (cur->u.regular.run.fontFace)
                 IDWriteFontFace_Release(cur->u.regular.run.fontFace);
-            heap_free(cur->u.regular.glyphs);
-            heap_free(cur->u.regular.clustermap);
-            heap_free(cur->u.regular.advances);
-            heap_free(cur->u.regular.offsets);
+            free(cur->u.regular.glyphs);
+            free(cur->u.regular.clustermap);
+            free(cur->u.regular.advances);
+            free(cur->u.regular.offsets);
         }
-        heap_free(cur);
+        free(cur);
     }
 }
 
@@ -585,25 +587,29 @@ static void free_layout_eruns(struct dwrite_textlayout *layout)
     struct layout_strikethrough *s, *s2;
     struct layout_underline *u, *u2;
 
-    LIST_FOR_EACH_ENTRY_SAFE(cur, cur2, &layout->eruns, struct layout_effective_run, entry) {
+    LIST_FOR_EACH_ENTRY_SAFE(cur, cur2, &layout->eruns, struct layout_effective_run, entry)
+    {
         list_remove(&cur->entry);
-        heap_free(cur->clustermap);
-        heap_free(cur);
+        free(cur->clustermap);
+        free(cur);
     }
 
-    LIST_FOR_EACH_ENTRY_SAFE(in, in2, &layout->inlineobjects, struct layout_effective_inline, entry) {
+    LIST_FOR_EACH_ENTRY_SAFE(in, in2, &layout->inlineobjects, struct layout_effective_inline, entry)
+    {
         list_remove(&in->entry);
-        heap_free(in);
+        free(in);
     }
 
-    LIST_FOR_EACH_ENTRY_SAFE(u, u2, &layout->underlines, struct layout_underline, entry) {
+    LIST_FOR_EACH_ENTRY_SAFE(u, u2, &layout->underlines, struct layout_underline, entry)
+    {
         list_remove(&u->entry);
-        heap_free(u);
+        free(u);
     }
 
-    LIST_FOR_EACH_ENTRY_SAFE(s, s2, &layout->strikethrough, struct layout_strikethrough, entry) {
+    LIST_FOR_EACH_ENTRY_SAFE(s, s2, &layout->strikethrough, struct layout_strikethrough, entry)
+    {
         list_remove(&s->entry);
-        heap_free(s);
+        free(s);
     }
 }
 
@@ -647,9 +653,9 @@ static HRESULT layout_update_breakpoints_range(struct dwrite_textlayout *layout,
     if (FAILED(hr))
         after = before = DWRITE_BREAK_CONDITION_NEUTRAL;
 
-    if (!layout->actual_breakpoints) {
-        layout->actual_breakpoints = heap_calloc(layout->len, sizeof(*layout->actual_breakpoints));
-        if (!layout->actual_breakpoints)
+    if (!layout->actual_breakpoints)
+    {
+        if (!(layout->actual_breakpoints = calloc(layout->len, sizeof(*layout->actual_breakpoints))))
             return E_OUTOFMEMORY;
         memcpy(layout->actual_breakpoints, layout->nominal_breakpoints, sizeof(DWRITE_LINE_BREAKPOINT)*layout->len);
     }
@@ -1020,18 +1026,18 @@ static void layout_shape_clear_user_features_context(struct shaping_context *con
 
     for (i = 0; i < context->user_features.range_count; ++i)
     {
-        heap_free(context->user_features.features[i]->features);
-        heap_free(context->user_features.features[i]);
+        free(context->user_features.features[i]->features);
+        free(context->user_features.features[i]);
     }
-    heap_free(context->user_features.features);
+    free(context->user_features.features);
     memset(&context->user_features, 0, sizeof(context->user_features));
 }
 
 static void layout_shape_clear_context(struct shaping_context *context)
 {
     layout_shape_clear_user_features_context(context);
-    heap_free(context->glyph_props);
-    heap_free(context->text_props);
+    free(context->glyph_props);
+    free(context->text_props);
 }
 
 static HRESULT layout_shape_add_empty_user_features_range(struct shaping_context *context, unsigned int length)
@@ -1039,7 +1045,7 @@ static HRESULT layout_shape_add_empty_user_features_range(struct shaping_context
     DWRITE_TYPOGRAPHIC_FEATURES *features;
     unsigned int r = context->user_features.range_count;
 
-    if (!(context->user_features.features[r] = heap_alloc_zero(sizeof(*features))))
+    if (!(context->user_features.features[r] = calloc(1, sizeof(*features))))
         return E_OUTOFMEMORY;
 
     context->user_features.range_lengths[r] = length;
@@ -1061,9 +1067,9 @@ static HRESULT layout_shape_get_user_features(struct dwrite_textlayout *layout,
     if (range->h.range.length >= run->descr.stringLength && !range->iface)
         return S_OK;
 
-    if (!(context->user_features.features = heap_calloc(run->descr.stringLength, sizeof(*context->user_features.features))))
+    if (!(context->user_features.features = calloc(run->descr.stringLength, sizeof(*context->user_features.features))))
         goto failed;
-    if (!(context->user_features.range_lengths = heap_calloc(run->descr.stringLength, sizeof(*context->user_features.range_lengths))))
+    if (!(context->user_features.range_lengths = calloc(run->descr.stringLength, sizeof(*context->user_features.range_lengths))))
         goto failed;
 
     for (i = run->descr.textPosition; i < run->descr.textPosition + run->descr.stringLength; ++i)
@@ -1087,13 +1093,13 @@ static HRESULT layout_shape_get_user_features(struct dwrite_textlayout *layout,
         }
 
         r = context->user_features.range_count;
-        if (!(features = context->user_features.features[r] = heap_alloc(sizeof(*features))))
+        if (!(features = context->user_features.features[r] = malloc(sizeof(*features))))
             goto failed;
 
         context->user_features.range_lengths[r] = length = min(run->descr.textPosition + run->descr.stringLength,
                 range->h.range.startPosition + range->h.range.length) - i;
         features->featureCount = feature_count;
-        if (!(features->features = heap_calloc(feature_count, sizeof(*features->features))))
+        if (!(features->features = calloc(feature_count, sizeof(*features->features))))
             goto failed;
 
         for (f = 0; f < feature_count; ++f)
@@ -1129,17 +1135,17 @@ static HRESULT layout_shape_get_glyphs(struct dwrite_textlayout *layout, struct
     HRESULT hr;
 
     run->descr.localeName = get_layout_range_by_pos(layout, run->descr.textPosition)->locale;
-    run->clustermap = heap_calloc(run->descr.stringLength, sizeof(*run->clustermap));
+    run->clustermap = calloc(run->descr.stringLength, sizeof(*run->clustermap));
     if (!run->clustermap)
         return E_OUTOFMEMORY;
 
     max_count = 3 * run->descr.stringLength / 2 + 16;
-    run->glyphs = heap_calloc(max_count, sizeof(*run->glyphs));
+    run->glyphs = calloc(max_count, sizeof(*run->glyphs));
     if (!run->glyphs)
         return E_OUTOFMEMORY;
 
-    context->text_props = heap_calloc(run->descr.stringLength, sizeof(*context->text_props));
-    context->glyph_props = heap_calloc(max_count, sizeof(*context->glyph_props));
+    context->text_props = calloc(run->descr.stringLength, sizeof(*context->text_props));
+    context->glyph_props = calloc(max_count, sizeof(*context->glyph_props));
     if (!context->text_props || !context->glyph_props)
         return E_OUTOFMEMORY;
 
@@ -1155,13 +1161,13 @@ static HRESULT layout_shape_get_glyphs(struct dwrite_textlayout *layout, struct
                 context->glyph_props, &run->glyphcount);
         if (hr == E_NOT_SUFFICIENT_BUFFER)
         {
-            heap_free(run->glyphs);
-            heap_free(context->glyph_props);
+            free(run->glyphs);
+            free(context->glyph_props);
 
             max_count *= 2;
 
-            run->glyphs = heap_calloc(max_count, sizeof(*run->glyphs));
-            context->glyph_props = heap_calloc(max_count, sizeof(*context->glyph_props));
+            run->glyphs = calloc(max_count, sizeof(*run->glyphs));
+            context->glyph_props = calloc(max_count, sizeof(*context->glyph_props));
             if (!run->glyphs || !context->glyph_props)
             {
                 hr = E_OUTOFMEMORY;
@@ -1211,7 +1217,8 @@ static HRESULT layout_shape_apply_character_spacing(struct dwrite_textlayout *la
     }
     if (!first) return S_OK;
 
-    if (!(clustermap = heap_calloc(run->descr.stringLength, sizeof(*clustermap)))) return E_OUTOFMEMORY;
+    if (!(clustermap = calloc(run->descr.stringLength, sizeof(*clustermap))))
+        return E_OUTOFMEMORY;
 
     pos = run->descr.textPosition;
 
@@ -1254,7 +1261,7 @@ static HRESULT layout_shape_apply_character_spacing(struct dwrite_textlayout *la
         if (cur == last) break;
     }
 
-    heap_free(clustermap);
+    free(clustermap);
 
     return S_OK;
 }
@@ -1264,8 +1271,8 @@ static HRESULT layout_shape_get_positions(struct dwrite_textlayout *layout, stru
     struct regular_layout_run *run = context->run;
     HRESULT hr;
 
-    run->advances = heap_calloc(run->glyphcount, sizeof(*run->advances));
-    run->offsets = heap_calloc(run->glyphcount, sizeof(*run->offsets));
+    run->advances = calloc(run->glyphcount, sizeof(*run->advances));
+    run->offsets = calloc(run->glyphcount, sizeof(*run->offsets));
     if (!run->advances || !run->offsets)
         return E_OUTOFMEMORY;
 
@@ -1334,12 +1341,14 @@ static HRESULT layout_compute_runs(struct dwrite_textlayout *layout)
     free_layout_runs(layout);
 
     /* Cluster data arrays are allocated once, assuming one text position per cluster. */
-    if (!layout->clustermetrics && layout->len) {
-        layout->clustermetrics = heap_calloc(layout->len, sizeof(*layout->clustermetrics));
-        layout->clusters = heap_calloc(layout->len, sizeof(*layout->clusters));
-        if (!layout->clustermetrics || !layout->clusters) {
-            heap_free(layout->clustermetrics);
-            heap_free(layout->clusters);
+    if (!layout->clustermetrics && layout->len)
+    {
+        layout->clustermetrics = calloc(layout->len, sizeof(*layout->clustermetrics));
+        layout->clusters = calloc(layout->len, sizeof(*layout->clusters));
+        if (!layout->clustermetrics || !layout->clusters)
+        {
+            free(layout->clustermetrics);
+            free(layout->clusters);
             return E_OUTOFMEMORY;
         }
     }
@@ -1424,8 +1433,7 @@ static HRESULT layout_compute(struct dwrite_textlayout *layout)
     {
         IDWriteTextAnalyzer2 *analyzer;
 
-        layout->nominal_breakpoints = heap_calloc(layout->len, sizeof(*layout->nominal_breakpoints));
-        if (!layout->nominal_breakpoints)
+        if (!(layout->nominal_breakpoints = calloc(layout->len, sizeof(*layout->nominal_breakpoints))))
             return E_OUTOFMEMORY;
 
         analyzer = get_text_analyzer();
@@ -1436,7 +1444,7 @@ static HRESULT layout_compute(struct dwrite_textlayout *layout)
             WARN("Line breakpoints analysis failed, hr %#x.\n", hr);
     }
 
-    heap_free(layout->actual_breakpoints);
+    free(layout->actual_breakpoints);
     layout->actual_breakpoints = NULL;
 
     hr = layout_compute_runs(layout);
@@ -1536,11 +1544,11 @@ static HRESULT layout_add_effective_run(struct dwrite_textlayout *layout, const
     UINT32 i, start, length, last_cluster;
     struct layout_effective_run *run;
 
-    if (r->kind == LAYOUT_RUN_INLINE) {
+    if (r->kind == LAYOUT_RUN_INLINE)
+    {
         struct layout_effective_inline *inlineobject;
 
-        inlineobject = heap_alloc(sizeof(*inlineobject));
-        if (!inlineobject)
+        if (!(inlineobject = malloc(sizeof(*inlineobject))))
             return E_OUTOFMEMORY;
 
         inlineobject->object = r->u.object.object;
@@ -1565,8 +1573,7 @@ static HRESULT layout_add_effective_run(struct dwrite_textlayout *layout, const
         return S_OK;
     }
 
-    run = heap_alloc(sizeof(*run));
-    if (!run)
+    if (!(run = malloc(sizeof(*run))))
         return E_OUTOFMEMORY;
 
     /* No need to iterate for that, use simple fact that:
@@ -1575,9 +1582,9 @@ static HRESULT layout_add_effective_run(struct dwrite_textlayout *layout, const
     length = layout->clusters[last_cluster].position - layout->clusters[first_cluster].position +
         layout->clustermetrics[last_cluster].length;
 
-    run->clustermap = heap_calloc(length, sizeof(*run->clustermap));
-    if (!run->clustermap) {
-        heap_free(run);
+    if (!(run->clustermap = calloc(length, sizeof(*run->clustermap))))
+    {
+        free(run);
         return E_OUTOFMEMORY;
     }
 
@@ -1618,12 +1625,12 @@ static HRESULT layout_add_effective_run(struct dwrite_textlayout *layout, const
     /* Strikethrough style is guaranteed to be consistent within effective run,
        its width equals to run width, thickness and offset are derived from
        font metrics, rest of the values are from layout or run itself */
-    if (params->strikethrough) {
+    if (params->strikethrough)
+    {
         struct layout_strikethrough *s;
         DWRITE_FONT_METRICS metrics;
 
-        s = heap_alloc(sizeof(*s));
-        if (!s)
+        if (!(s = malloc(sizeof(*s))))
             return E_OUTOFMEMORY;
 
         layout_get_erun_font_metrics(layout, run, &metrics);
@@ -2021,8 +2028,7 @@ static HRESULT layout_add_underline(struct dwrite_textlayout *layout, struct lay
             cur = next;
         }
 
-        u = heap_alloc(sizeof(*u));
-        if (!u)
+        if (!(u = malloc(sizeof(*u))))
             return E_OUTOFMEMORY;
 
         w = cur;
@@ -2200,8 +2206,7 @@ static void layout_add_line(struct dwrite_textlayout *layout, UINT32 first_clust
     if (append_trimming_run) {
         struct layout_effective_inline *trimming_sign;
 
-        trimming_sign = heap_alloc(sizeof(*trimming_sign));
-        if (!trimming_sign)
+        if (!(trimming_sign = calloc(1, sizeof(*trimming_sign))))
             return;
 
         trimming_sign->object = layout->format.trimmingsign;
@@ -2506,18 +2511,18 @@ static struct layout_range_header *alloc_layout_range(struct dwrite_textlayout *
     {
         struct layout_range *range;
 
-        range = heap_alloc_zero(sizeof(*range));
-        if (!range) return NULL;
+        if (!(range = calloc(1, sizeof(*range))))
+            return NULL;
 
         range->weight = layout->format.weight;
         range->style  = layout->format.style;
         range->stretch = layout->format.stretch;
         range->fontsize = layout->format.fontsize;
 
-        range->fontfamily = heap_strdupW(layout->format.family_name);
+        range->fontfamily = wcsdup(layout->format.family_name);
         if (!range->fontfamily)
         {
-            heap_free(range);
+            free(range);
             return NULL;
         }
 
@@ -2534,8 +2539,8 @@ static struct layout_range_header *alloc_layout_range(struct dwrite_textlayout *
     {
         struct layout_range_bool *range;
 
-        range = heap_alloc_zero(sizeof(*range));
-        if (!range) return NULL;
+        if (!(range = calloc(1, sizeof(*range))))
+            return NULL;
 
         h = &range->h;
         break;
@@ -2545,8 +2550,8 @@ static struct layout_range_header *alloc_layout_range(struct dwrite_textlayout *
     {
         struct layout_range_iface *range;
 
-        range = heap_alloc_zero(sizeof(*range));
-        if (!range) return NULL;
+        if (!(range = calloc(1, sizeof(*range))))
+            return NULL;
 
         h = &range->h;
         break;
@@ -2555,8 +2560,8 @@ static struct layout_range_header *alloc_layout_range(struct dwrite_textlayout *
     {
         struct layout_range_spacing *range;
 
-        range = heap_alloc_zero(sizeof(*range));
-        if (!range) return NULL;
+        if (!(range = calloc(1, sizeof(*range))))
+            return NULL;
 
         h = &range->h;
         break;
@@ -2579,15 +2584,16 @@ static struct layout_range_header *alloc_layout_range_from(struct layout_range_h
     {
     case LAYOUT_RANGE_REGULAR:
     {
-        struct layout_range *from = (struct layout_range*)h;
+        struct layout_range *from = (struct layout_range *)h, *range;
 
-        struct layout_range *range = heap_alloc(sizeof(*range));
-        if (!range) return NULL;
+        if (!(range = malloc(sizeof(*range))))
+            return NULL;
 
         *range = *from;
-        range->fontfamily = heap_strdupW(from->fontfamily);
-        if (!range->fontfamily) {
-            heap_free(range);
+        range->fontfamily = wcsdup(from->fontfamily);
+        if (!range->fontfamily)
+        {
+            free(range);
             return NULL;
         }
 
@@ -2602,7 +2608,7 @@ static struct layout_range_header *alloc_layout_range_from(struct layout_range_h
     case LAYOUT_RANGE_UNDERLINE:
     case LAYOUT_RANGE_STRIKETHROUGH:
     {
-        struct layout_range_bool *strike = heap_alloc(sizeof(*strike));
+        struct layout_range_bool *strike = malloc(sizeof(*strike));
         if (!strike) return NULL;
 
         *strike = *(struct layout_range_bool*)h;
@@ -2612,7 +2618,7 @@ static struct layout_range_header *alloc_layout_range_from(struct layout_range_h
     case LAYOUT_RANGE_EFFECT:
     case LAYOUT_RANGE_TYPOGRAPHY:
     {
-        struct layout_range_iface *effect = heap_alloc(sizeof(*effect));
+        struct layout_range_iface *effect = malloc(sizeof(*effect));
         if (!effect) return NULL;
 
         *effect = *(struct layout_range_iface*)h;
@@ -2623,7 +2629,7 @@ static struct layout_range_header *alloc_layout_range_from(struct layout_range_h
     }
     case LAYOUT_RANGE_SPACING:
     {
-        struct layout_range_spacing *spacing = heap_alloc(sizeof(*spacing));
+        struct layout_range_spacing *spacing = malloc(sizeof(*spacing));
         if (!spacing) return NULL;
 
         *spacing = *(struct layout_range_spacing*)h;
@@ -2654,7 +2660,7 @@ static void free_layout_range(struct layout_range_header *h)
             IDWriteInlineObject_Release(range->object);
         if (range->collection)
             IDWriteFontCollection_Release(range->collection);
-        heap_free(range->fontfamily);
+        free(range->fontfamily);
         break;
     }
     case LAYOUT_RANGE_EFFECT:
@@ -2669,7 +2675,7 @@ static void free_layout_range(struct layout_range_header *h)
         ;
     }
 
-    heap_free(h);
+    free(h);
 }
 
 static void free_layout_ranges_list(struct dwrite_textlayout *layout)
@@ -2798,8 +2804,8 @@ static BOOL set_layout_range_attrval(struct layout_range_header *h, enum layout_
         changed = !!wcscmp(dest->fontfamily, value->u.fontfamily);
         if (changed)
         {
-            heap_free(dest->fontfamily);
-            dest->fontfamily = heap_strdupW(value->u.fontfamily);
+            free(dest->fontfamily);
+            dest->fontfamily = wcsdup(value->u.fontfamily);
         }
         break;
     case LAYOUT_RANGE_ATTR_SPACING:
@@ -3115,13 +3121,13 @@ static ULONG WINAPI dwritetextlayout_Release(IDWriteTextLayout4 *iface)
         free_layout_eruns(layout);
         free_layout_runs(layout);
         release_format_data(&layout->format);
-        heap_free(layout->nominal_breakpoints);
-        heap_free(layout->actual_breakpoints);
-        heap_free(layout->clustermetrics);
-        heap_free(layout->clusters);
-        heap_free(layout->lines);
-        heap_free(layout->str);
-        heap_free(layout);
+        free(layout->nominal_breakpoints);
+        free(layout->actual_breakpoints);
+        free(layout->clustermetrics);
+        free(layout->clusters);
+        free(layout->lines);
+        free(layout->str);
+        free(layout);
     }
 
     return refcount;
@@ -3946,13 +3952,13 @@ static void layout_get_erun_bbox(struct dwrite_textlayout *layout, struct layout
 
         bbox = &glyph_bitmap.bbox;
 
-        if (!(origins = heap_calloc(glyph_run.glyphCount, sizeof(*origins))))
+        if (!(origins = calloc(glyph_run.glyphCount, sizeof(*origins))))
             return;
 
         if (FAILED(hr = compute_glyph_origins(&glyph_run, layout->measuringmode, baseline_origin, &layout->transform, origins)))
         {
             WARN("Failed to compute glyph origins, hr %#x.\n", hr);
-            heap_free(origins);
+            free(origins);
             return;
         }
 
@@ -3972,7 +3978,7 @@ static void layout_get_erun_bbox(struct dwrite_textlayout *layout, struct layout
             d2d_rect_union(&run->bbox, &glyph_bbox);
         }
 
-        heap_free(origins);
+        free(origins);
     }
 
     *bbox = run->bbox;
@@ -5335,12 +5341,12 @@ static HRESULT layout_format_from_textformat(struct dwrite_textlayout *layout, I
     if ((textformat = unsafe_impl_from_IDWriteTextFormat(format))) {
         layout->format = textformat->format;
 
-        layout->format.locale = heap_strdupW(textformat->format.locale);
-        layout->format.family_name = heap_strdupW(textformat->format.family_name);
+        layout->format.locale = wcsdup(textformat->format.locale);
+        layout->format.family_name = wcsdup(textformat->format.family_name);
         if (!layout->format.locale || !layout->format.family_name)
         {
-            heap_free(layout->format.locale);
-            heap_free(layout->format.family_name);
+            free(layout->format.locale);
+            free(layout->format.family_name);
             return E_OUTOFMEMORY;
         }
 
@@ -5375,8 +5381,7 @@ static HRESULT layout_format_from_textformat(struct dwrite_textlayout *layout, I
 
     /* locale name and length */
     len = IDWriteTextFormat_GetLocaleNameLength(format);
-    layout->format.locale = heap_alloc((len+1)*sizeof(WCHAR));
-    if (!layout->format.locale)
+    if (!(layout->format.locale = malloc((len + 1) * sizeof(WCHAR))))
         return E_OUTOFMEMORY;
 
     hr = IDWriteTextFormat_GetLocaleName(format, layout->format.locale, len+1);
@@ -5386,8 +5391,7 @@ static HRESULT layout_format_from_textformat(struct dwrite_textlayout *layout, I
 
     /* font family name and length */
     len = IDWriteTextFormat_GetFontFamilyNameLength(format);
-    layout->format.family_name = heap_alloc((len+1)*sizeof(WCHAR));
-    if (!layout->format.family_name)
+    if (!(layout->format.family_name = malloc((len + 1) * sizeof(WCHAR))))
         return E_OUTOFMEMORY;
 
     hr = IDWriteTextFormat_GetFontFamilyName(format, layout->format.family_name, len+1);
@@ -5509,7 +5513,7 @@ HRESULT create_textlayout(const struct textlayout_desc *desc, IDWriteTextLayout
     if (!desc->format || !desc->string)
         return E_INVALIDARG;
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     hr = init_textlayout(desc, object);
@@ -5555,7 +5559,7 @@ static ULONG WINAPI dwritetrimmingsign_Release(IDWriteInlineObject *iface)
     if (!refcount)
     {
         IDWriteTextLayout_Release(sign->layout);
-        heap_free(sign);
+        free(sign);
     }
 
     return refcount;
@@ -5672,7 +5676,7 @@ HRESULT create_trimmingsign(IDWriteFactory7 *factory, IDWriteTextFormat *format,
         (is_reading_direction_vert(reading) && is_flow_direction_vert(flow)))
         return DWRITE_E_FLOWDIRECTIONCONFLICTS;
 
-    if (!(object = heap_alloc(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteInlineObject_iface.lpVtbl = &dwritetrimmingsignvtbl;
@@ -5681,7 +5685,7 @@ HRESULT create_trimmingsign(IDWriteFactory7 *factory, IDWriteTextFormat *format,
     hr = IDWriteFactory7_CreateTextLayout(factory, &ellipsisW, 1, format, 0.0f, 0.0f, &object->layout);
     if (FAILED(hr))
     {
-        heap_free(object);
+        free(object);
         return hr;
     }
 
@@ -5736,7 +5740,7 @@ static ULONG WINAPI dwritetextformat_Release(IDWriteTextFormat3 *iface)
     if (!refcount)
     {
         release_format_data(&format->format);
-        heap_free(format);
+        free(format);
     }
 
     return refcount;
@@ -6208,14 +6212,14 @@ HRESULT create_textformat(const WCHAR *family_name, IDWriteFontCollection *colle
         ((UINT32)style > DWRITE_FONT_STYLE_ITALIC))
         return E_INVALIDARG;
 
-    if (!(object = heap_alloc_zero(sizeof(*object))))
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteTextFormat3_iface.lpVtbl = &dwritetextformatvtbl;
     object->refcount = 1;
-    object->format.family_name = heap_strdupW(family_name);
+    object->format.family_name = wcsdup(family_name);
     object->format.family_len = wcslen(family_name);
-    object->format.locale = heap_strdupW(locale);
+    object->format.locale = wcsdup(locale);
     object->format.locale_len = wcslen(locale);
     /* Force locale name to lower case, layout will inherit this modified value. */
     wcslwr(object->format.locale);
@@ -6269,8 +6273,8 @@ static ULONG WINAPI dwritetypography_Release(IDWriteTypography *iface)
 
     if (!refcount)
     {
-        heap_free(typography->features);
-        heap_free(typography);
+        free(typography->features);
+        free(typography);
     }
 
     return refcount;
@@ -6331,8 +6335,7 @@ HRESULT create_typography(IDWriteTypography **ret)
 
     *ret = NULL;
 
-    typography = heap_alloc_zero(sizeof(*typography));
-    if (!typography)
+    if (!(typography = calloc(1, sizeof(*typography))))
         return E_OUTOFMEMORY;
 
     typography->IDWriteTypography_iface.lpVtbl = &dwritetypographyvtbl;
diff --git a/dlls/dwrite/main.c b/dlls/dwrite/main.c
index 2a0b69400f4..d0dd4dd99e9 100644
--- a/dlls/dwrite/main.c
+++ b/dlls/dwrite/main.c
@@ -113,7 +113,7 @@ static ULONG WINAPI renderingparams_Release(IDWriteRenderingParams3 *iface)
     TRACE("%p, refcount %d.\n", iface, refcount);
 
     if (!refcount)
-        heap_free(params);
+        free(params);
 
     return refcount;
 }
@@ -235,7 +235,7 @@ static HRESULT create_renderingparams(float gamma, float contrast, float graysca
     if ((UINT32)gridfit > DWRITE_GRID_FIT_MODE_ENABLED || (UINT32)geometry > DWRITE_PIXEL_GEOMETRY_BGR)
         return E_INVALIDARG;
 
-    if (!(object = heap_alloc(sizeof(*object))))
+    if (!(object = malloc(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteRenderingParams3_iface.lpVtbl = &renderingparamsvtbl;
@@ -312,12 +312,12 @@ static ULONG WINAPI localizedstrings_Release(IDWriteLocalizedStrings *iface)
     {
         for (i = 0; i < strings->count; ++i)
         {
-            heap_free(strings->data[i].locale);
-            heap_free(strings->data[i].string);
+            free(strings->data[i].locale);
+            free(strings->data[i].string);
         }
 
-        heap_free(strings->data);
-        heap_free(strings);
+        free(strings->data);
+        free(strings);
     }
 
     return refcount;
@@ -449,8 +449,7 @@ HRESULT create_localizedstrings(IDWriteLocalizedStrings **strings)
 
     *strings = NULL;
 
-    object = heap_alloc_zero(sizeof(*object));
-    if (!object)
+    if (!(object = calloc(1, sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->IDWriteLocalizedStrings_iface.lpVtbl = &localizedstringsvtbl;
@@ -477,12 +476,12 @@ HRESULT add_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *locale,
     if (!dwrite_array_reserve((void **)&strings->data, &strings->size, strings->count + 1, sizeof(*strings->data)))
         return E_OUTOFMEMORY;
 
-    strings->data[count].locale = heap_strdupW(locale);
-    strings->data[count].string = heap_strdupW(string);
+    strings->data[count].locale = wcsdup(locale);
+    strings->data[count].string = wcsdup(string);
     if (!strings->data[count].locale || !strings->data[count].string)
     {
-        heap_free(strings->data[count].locale);
-        heap_free(strings->data[count].string);
+        free(strings->data[count].locale);
+        free(strings->data[count].string);
         return E_OUTOFMEMORY;
     }
     wcslwr(strings->data[count].locale);
@@ -503,14 +502,13 @@ HRESULT clone_localizedstrings(IDWriteLocalizedStrings *iface, IDWriteLocalizedS
         return S_FALSE;
 
     strings = impl_from_IDWriteLocalizedStrings(iface);
-    strings_clone = heap_alloc_zero(sizeof(*strings_clone));
-    if (!strings_clone)
+    if (!(strings_clone = calloc(1, sizeof(*strings_clone))))
         return E_OUTOFMEMORY;
 
     if (!dwrite_array_reserve((void **)&strings_clone->data, &strings_clone->size, strings->count,
             sizeof(*strings_clone->data)))
     {
-        heap_free(strings_clone);
+        free(strings_clone);
         return E_OUTOFMEMORY;
     }
 
@@ -520,8 +518,8 @@ HRESULT clone_localizedstrings(IDWriteLocalizedStrings *iface, IDWriteLocalizedS
 
     for (i = 0; i < strings_clone->count; ++i)
     {
-        strings_clone->data[i].locale = heap_strdupW(strings->data[i].locale);
-        strings_clone->data[i].string = heap_strdupW(strings->data[i].string);
+        strings_clone->data[i].locale = wcsdup(strings->data[i].locale);
+        strings_clone->data[i].string = wcsdup(strings->data[i].string);
     }
 
     *ret = &strings_clone->IDWriteLocalizedStrings_iface;
@@ -538,8 +536,8 @@ void set_en_localizedstring(IDWriteLocalizedStrings *iface, const WCHAR *string)
     {
         if (!wcsicmp(strings->data[i].locale, L"en-US"))
         {
-            heap_free(strings->data[i].string);
-            strings->data[i].string = heap_strdupW(string);
+            free(strings->data[i].string);
+            strings->data[i].string = wcsdup(string);
             break;
         }
     }
@@ -622,7 +620,7 @@ static void release_fontface_cache(struct list *fontfaces)
     LIST_FOR_EACH_ENTRY_SAFE(fontface, fontface2, fontfaces, struct fontfacecached, entry) {
         list_remove(&fontface->entry);
         fontface_detach_from_cache(fontface->fontface);
-        heap_free(fontface);
+        free(fontface);
     }
 }
 
@@ -631,7 +629,7 @@ static void release_fileloader(struct fileloader *fileloader)
     list_remove(&fileloader->entry);
     release_fontface_cache(&fileloader->fontfaces);
     IDWriteFontFileLoader_Release(fileloader->loader);
-    heap_free(fileloader);
+    free(fileloader);
 }
 
 static void release_dwritefactory(struct dwritefactory *factory)
@@ -646,7 +644,7 @@ static void release_dwritefactory(struct dwritefactory *factory)
     LIST_FOR_EACH_ENTRY_SAFE(loader, loader2, &factory->collection_loaders, struct collectionloader, entry) {
         list_remove(&loader->entry);
         IDWriteFontCollectionLoader_Release(loader->loader);
-        heap_free(loader);
+        free(loader);
     }
 
     LIST_FOR_EACH_ENTRY_SAFE(fileloader, fileloader2, &factory->file_loaders, struct fileloader, entry)
@@ -661,7 +659,7 @@ static void release_dwritefactory(struct dwritefactory *factory)
 
     factory->cs.DebugInfo->Spare[0] = 0;
     DeleteCriticalSection(&factory->cs);
-    heap_free(factory);
+    free(factory);
 }
 
 static void release_shared_factory(IDWriteFactory7 *iface)
@@ -820,8 +818,7 @@ static HRESULT WINAPI dwritefactory_RegisterFontCollectionLoader(IDWriteFactory7
     if (factory_get_collection_loader(factory, loader))
         return DWRITE_E_ALREADYREGISTERED;
 
-    entry = heap_alloc(sizeof(*entry));
-    if (!entry)
+    if (!(entry = malloc(sizeof(*entry))))
         return E_OUTOFMEMORY;
 
     entry->loader = loader;
@@ -848,7 +845,7 @@ static HRESULT WINAPI dwritefactory_UnregisterFontCollectionLoader(IDWriteFactor
 
     IDWriteFontCollectionLoader_Release(found->loader);
     list_remove(&found->entry);
-    heap_free(found);
+    free(found);
 
     return S_OK;
 }
@@ -871,7 +868,7 @@ static HRESULT WINAPI dwritefactory_CreateFontFileReference(IDWriteFactory7 *ifa
         return hr;
 
     hr = create_font_file(factory->localfontfileloader, key, key_size, font_file);
-    heap_free(key);
+    free(key);
 
     return hr;
 }
@@ -986,8 +983,7 @@ struct fontfacecached *factory_cache_fontface(IDWriteFactory7 *iface, struct lis
     struct fontfacecached *cached;
 
     /* new cache entry */
-    cached = heap_alloc(sizeof(*cached));
-    if (!cached)
+    if (!(cached = malloc(sizeof(*cached))))
         return NULL;
 
     cached->fontface = fontface;
@@ -1128,8 +1124,7 @@ static HRESULT WINAPI dwritefactory_RegisterFontFileLoader(IDWriteFactory7 *ifac
     if (factory_get_file_loader(factory, loader))
         return DWRITE_E_ALREADYREGISTERED;
 
-    entry = heap_alloc(sizeof(*entry));
-    if (!entry)
+    if (!(entry = malloc(sizeof(*entry))))
         return E_OUTOFMEMORY;
 
     entry->loader = loader;
@@ -1525,17 +1520,17 @@ static HRESULT create_system_path_list(WCHAR ***ret, unsigned int *ret_count)
     }
 
     value_size = MAX_PATH * sizeof(*value);
-    value = heap_alloc(value_size);
+    value = malloc(value_size);
 
     max_name_count = MAX_PATH;
-    name = heap_alloc(max_name_count * sizeof(*name));
+    name = malloc(max_name_count * sizeof(*name));
 
     for (;;)
     {
         if (!value)
         {
             value_size = MAX_PATH * sizeof(*value);
-            value = heap_alloc(value_size);
+            value = malloc(value_size);
         }
 
         do
@@ -1549,15 +1544,15 @@ static HRESULT create_system_path_list(WCHAR ***ret, unsigned int *ret_count)
                 if (name_count >= max_name_count)
                 {
                     max_name_count *= 2;
-                    heap_free(name);
-                    name = heap_alloc(max_name_count * sizeof(*name));
+                    free(name);
+                    name = malloc(max_name_count * sizeof(*name));
                 }
 
                 if (data_size > value_size - sizeof(*value))
                 {
-                    heap_free(value);
+                    free(value);
                     value_size = max(data_size + sizeof(*value), value_size * 2);
-                    value = heap_alloc(value_size);
+                    value = malloc(value_size);
                 }
             }
         } while (r == ERROR_MORE_DATA);
@@ -1574,12 +1569,12 @@ static HRESULT create_system_path_list(WCHAR ***ret, unsigned int *ret_count)
                 {
                     WCHAR *ptrW;
 
-                    ptrW = heap_alloc((MAX_PATH + wcslen(value)) * sizeof(WCHAR));
+                    ptrW = malloc((MAX_PATH + wcslen(value)) * sizeof(WCHAR));
                     GetWindowsDirectoryW(ptrW, MAX_PATH);
                     wcscat(ptrW, L"\\fonts\\");
                     wcscat(ptrW, value);
 
-                    heap_free(value);
+                    free(value);
                     value = ptrW;
                 }
 
@@ -1590,8 +1585,8 @@ static HRESULT create_system_path_list(WCHAR ***ret, unsigned int *ret_count)
         index++;
     }
 
-    heap_free(value);
-    heap_free(name);
+    free(value);
+    free(name);
 
     *ret = paths;
     *ret_count = count;
@@ -1636,8 +1631,8 @@ static HRESULT create_system_fontset(IDWriteFactory7 *factory, REFIID riid, void
         }
 
         for (i = 0; i < count; ++i)
-            heap_free(paths[i]);
-        heap_free(paths);
+            free(paths[i]);
+        free(paths);
     }
 
     if (SUCCEEDED(hr = IDWriteFontSetBuilder2_CreateFontSet(builder, &fontset)))
@@ -2075,8 +2070,8 @@ HRESULT WINAPI DWriteCreateFactory(DWRITE_FACTORY_TYPE type, REFIID riid, IUnkno
     if (type == DWRITE_FACTORY_TYPE_SHARED && shared_factory)
         return IDWriteFactory7_QueryInterface(shared_factory, riid, (void**)ret);
 
-    factory = heap_alloc(sizeof(struct dwritefactory));
-    if (!factory) return E_OUTOFMEMORY;
+    if (!(factory = calloc(1, sizeof(*factory))))
+        return E_OUTOFMEMORY;
 
     init_dwritefactory(factory, type);
 
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c
index d7f8701fbbe..452b00240b8 100644
--- a/dlls/dwrite/opentype.c
+++ b/dlls/dwrite/opentype.c
@@ -2332,7 +2332,7 @@ static BOOL opentype_decode_namerecord(const struct dwrite_fonttable *table, uns
         if (codepage)
         {
             DWORD len = MultiByteToWideChar(codepage, 0, name, length, NULL, 0);
-            name_string = heap_alloc(sizeof(WCHAR) * (len+1));
+            name_string = malloc(sizeof(WCHAR) * (len+1));
             MultiByteToWideChar(codepage, 0, name, length, name_string, len);
             name_string[len] = 0;
         }
@@ -2346,7 +2346,7 @@ static BOOL opentype_decode_namerecord(const struct dwrite_fonttable *table, uns
 
         TRACE("string %s for locale %s found\n", debugstr_w(name_string), debugstr_w(locale));
         add_localizedstring(strings, locale, name_string);
-        heap_free(name_string);
+        free(name_string);
 
         ret = !wcscmp(locale, L"en-US");
     }
@@ -2507,9 +2507,9 @@ static HRESULT opentype_get_font_strings_from_meta(const struct file_stream_desc
 
                 if ((data = table_read_ensure(&meta, GET_BE_DWORD(maps[i].offset), length)))
                 {
-                    WCHAR *ptrW = heap_alloc((length + 1) * sizeof(WCHAR)), *ctx, *token;
+                    WCHAR *ptrW, *ctx, *token;
 
-                    if (!ptrW)
+                    if (!(ptrW = malloc((length + 1) * sizeof(WCHAR))))
                     {
                         hr = E_OUTOFMEMORY;
                         goto end;
@@ -2528,7 +2528,7 @@ static HRESULT opentype_get_font_strings_from_meta(const struct file_stream_desc
                         token = meta_get_lng_name(NULL, &ctx);
                     }
 
-                    heap_free(ptrW);
+                    free(ptrW);
                 }
             }
         }
@@ -2644,13 +2644,13 @@ HRESULT opentype_get_font_facename(struct file_stream_desc *stream_desc, WCHAR *
             WCHAR *nameW;
 
             IDWriteLocalizedStrings_GetStringLength(lfnames, index, &length);
-            nameW = heap_alloc((length + 1) * sizeof(WCHAR));
+            nameW = malloc((length + 1) * sizeof(WCHAR));
             if (nameW)
             {
                 *nameW = 0;
                 IDWriteLocalizedStrings_GetString(lfnames, index, nameW, length + 1);
                 lstrcpynW(lfname, nameW, LF_FACESIZE);
-                heap_free(nameW);
+                free(nameW);
             }
         }
 
@@ -4880,7 +4880,7 @@ void opentype_layout_apply_gpos_features(struct scriptshaping_context *context,
         }
     }
 
-    heap_free(lookups.lookups);
+    free(lookups.lookups);
 
     if (context->has_gpos_attachment)
     {
@@ -4955,11 +4955,11 @@ static BOOL opentype_layout_gsub_ensure_buffer(struct scriptshaping_context *con
 
     new_capacity = context->u.subst.capacity * 2;
 
-    if ((glyphs = heap_realloc(context->u.subst.glyphs, new_capacity * sizeof(*glyphs))))
+    if ((glyphs = realloc(context->u.subst.glyphs, new_capacity * sizeof(*glyphs))))
         context->u.subst.glyphs = glyphs;
-    if ((glyph_props = heap_realloc(context->u.subst.glyph_props, new_capacity * sizeof(*glyph_props))))
+    if ((glyph_props = realloc(context->u.subst.glyph_props, new_capacity * sizeof(*glyph_props))))
         context->u.subst.glyph_props = glyph_props;
-    if ((glyph_infos = heap_realloc(context->glyph_infos, new_capacity * sizeof(*glyph_infos))))
+    if ((glyph_infos = realloc(context->glyph_infos, new_capacity * sizeof(*glyph_infos))))
         context->glyph_infos = glyph_infos;
 
     if ((ret = (glyphs && glyph_props && glyph_infos)))
@@ -6110,7 +6110,7 @@ void opentype_layout_apply_gsub_features(struct scriptshaping_context *context,
     for (j = context->glyph_infos[start_idx].start_text_idx; j < context->length; ++j)
         context->u.buffer.clustermap[j] = start_idx;
 
-    heap_free(lookups.lookups);
+    free(lookups.lookups);
 }
 
 static BOOL opentype_layout_contextual_lookup_is_glyph_covered(struct scriptshaping_context *context, UINT16 glyph,
@@ -6339,7 +6339,7 @@ BOOL opentype_layout_check_feature(struct scriptshaping_context *context, unsign
             break;
     }
 
-    heap_free(lookups.lookups);
+    free(lookups.lookups);
 
     return ret;
 }
@@ -6396,7 +6396,7 @@ BOOL opentype_has_vertical_variants(struct dwrite_fontface *fontface)
         }
     }
 
-    heap_free(lookups.lookups);
+    free(lookups.lookups);
 
     if (count)
         fontface->flags |= FONTFACE_VERTICAL_VARIANTS;
@@ -6422,10 +6422,10 @@ HRESULT opentype_get_vertical_glyph_variants(struct dwrite_fontface *fontface, u
 
     context.cache = fontface_get_shaping_cache(fontface);
     context.u.subst.glyphs = glyphs;
-    context.u.subst.glyph_props = heap_calloc(glyph_count, sizeof(*context.u.subst.glyph_props));
+    context.u.subst.glyph_props = calloc(glyph_count, sizeof(*context.u.subst.glyph_props));
     context.u.subst.max_glyph_count = glyph_count;
     context.u.subst.capacity = glyph_count;
-    context.glyph_infos = heap_alloc_zero(sizeof(*context.glyph_infos) * glyph_count);
+    context.glyph_infos = calloc(glyph_count, sizeof(*context.glyph_infos));
     context.table = &context.cache->gsub;
 
     vert_feature.tag = DWRITE_MAKE_OPENTYPE_TAG('v','e','r','t');
@@ -6456,9 +6456,9 @@ HRESULT opentype_get_vertical_glyph_variants(struct dwrite_fontface *fontface, u
         }
     }
 
-    heap_free(context.u.subst.glyph_props);
-    heap_free(context.glyph_infos);
-    heap_free(lookups.lookups);
+    free(context.u.subst.glyph_props);
+    free(context.glyph_infos);
+    free(lookups.lookups);
 
     return S_OK;
 }
diff --git a/dlls/dwrite/shape.c b/dlls/dwrite/shape.c
index 2d098fb5688..177ad1d06fe 100644
--- a/dlls/dwrite/shape.c
+++ b/dlls/dwrite/shape.c
@@ -44,8 +44,7 @@ struct scriptshaping_cache *create_scriptshaping_cache(void *context, const stru
 {
     struct scriptshaping_cache *cache;
 
-    cache = heap_alloc_zero(sizeof(*cache));
-    if (!cache)
+    if (!(cache = calloc(1, sizeof(*cache))))
         return NULL;
 
     cache->font = font_ops;
@@ -65,7 +64,7 @@ void release_scriptshaping_cache(struct scriptshaping_cache *cache)
     cache->font->release_font_table(cache->context, cache->gdef.table.context);
     cache->font->release_font_table(cache->context, cache->gsub.table.context);
     cache->font->release_font_table(cache->context, cache->gpos.table.context);
-    heap_free(cache);
+    free(cache);
 }
 
 static unsigned int shape_select_script(const struct scriptshaping_cache *cache, DWORD kind, const DWORD *scripts,
@@ -269,7 +268,7 @@ HRESULT shape_get_positions(struct scriptshaping_context *context, const unsigne
         if (context->u.pos.glyph_props[i].isZeroWidthSpace)
             context->advances[i] = 0.0f;
 
-    heap_free(features.features);
+    free(features.features);
 
     return S_OK;
 }
@@ -347,7 +346,7 @@ HRESULT shape_get_glyphs(struct scriptshaping_context *context, const unsigned i
     shape_get_script_lang_index(context, scripts, MS_GSUB_TAG, &script_index, &language_index);
     opentype_layout_apply_gsub_features(context, script_index, language_index, &features);
 
-    heap_free(features.features);
+    free(features.features);
 
     return (context->glyph_count <= context->u.subst.max_glyph_count) ? S_OK : E_NOT_SUFFICIENT_BUFFER;
 }
@@ -393,7 +392,7 @@ HRESULT shape_get_typographic_features(struct scriptshaping_context *context, co
 
     *actual_tagcount = t.count;
 
-    heap_free(t.tags);
+    free(t.tags);
 
     return t.count <= max_tagcount ? S_OK : E_NOT_SUFFICIENT_BUFFER;
 }
-- 
2.33.0




More information about the wine-devel mailing list