From 8179ff5d7ba4a140cf6743729a22072800e98a79 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 27 Jun 2016 03:54:15 +0430 Subject: [PATCH] [dwrite] Don't allocate more than needed Addressing Nikolay Sivov reviews on harfbuzz mailing list --- src/hb-directwrite.cc | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/hb-directwrite.cc b/src/hb-directwrite.cc index 36b4d5d..09889d0 100644 --- a/src/hb-directwrite.cc +++ b/src/hb-directwrite.cc @@ -664,11 +664,11 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan, (const DWRITE_TYPOGRAPHIC_FEATURES*) &singleFeatures; const uint32_t featureRangeLengths[] = { textLength }; + uint16_t* clusterMap = (uint16_t*) malloc (textLength * sizeof (uint16_t)); + DWRITE_SHAPING_TEXT_PROPERTIES* textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*) + malloc (textLength * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES)); retry_getglyphs: - uint16_t* clusterMap = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t)); uint16_t* glyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t)); - DWRITE_SHAPING_TEXT_PROPERTIES* textProperties = (DWRITE_SHAPING_TEXT_PROPERTIES*) - malloc (maxGlyphCount * sizeof (DWRITE_SHAPING_TEXT_PROPERTIES)); DWRITE_SHAPING_GLYPH_PROPERTIES* glyphProperties = (DWRITE_SHAPING_GLYPH_PROPERTIES*) malloc (maxGlyphCount * sizeof (DWRITE_SHAPING_GLYPH_PROPERTIES)); @@ -679,9 +679,7 @@ retry_getglyphs: if (unlikely (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER))) { - free (clusterMap); free (glyphIndices); - free (textProperties); free (glyphProperties); maxGlyphCount *= 2; @@ -779,10 +777,10 @@ retry_getglyphs: // if a script justificationCharacter is not space, it can have GetJustifiedGlyphs if (justificationCharacter != 32) { + uint16_t* modifiedClusterMap = (uint16_t*) malloc (textLength * sizeof (uint16_t)); retry_getjustifiedglyphs: - uint16_t* modifiedClusterMap = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t)); - uint16_t* modifiedGlyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof(uint16_t)); - float* modifiedGlyphAdvances = (float*) malloc (maxGlyphCount * sizeof(float)); + uint16_t* modifiedGlyphIndices = (uint16_t*) malloc (maxGlyphCount * sizeof (uint16_t)); + float* modifiedGlyphAdvances = (float*) malloc (maxGlyphCount * sizeof (float)); DWRITE_GLYPH_OFFSET* modifiedGlyphOffsets = (DWRITE_GLYPH_OFFSET*) malloc (maxGlyphCount * sizeof (DWRITE_GLYPH_OFFSET)); uint32_t actualGlyphsCount; @@ -795,7 +793,6 @@ retry_getglyphs: if (hr == HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER)) { maxGlyphCount = actualGlyphsCount; - free (modifiedClusterMap); free (modifiedGlyphIndices); free (modifiedGlyphAdvances); free (modifiedGlyphOffsets); -- 2.7.4