From 0600f7d6299a21014f1b72d54fc6b23c02693204 Mon Sep 17 00:00:00 2001
From: Konstantin Ritt <ritt.ks@gmail.com>
Date: Fri, 14 Nov 2014 14:15:04 +0400
Subject: [PATCH] Fix hb_face leaking in QFontEngineFT

Since HarfBuzz-old's HB_Face doesn't support ref-counting,
it is impossible to keep the same behavior as for NG's ref-counted hb_face
when we're going to reparent the data of unknown type in QFontEngineFT.

We should either not release the object returned by harfbuzzFace(),
or introduce ref-counting for HB-old's HB_Face. Stop referencing HB-NG's
objects on access for now and thus avoid a need to release them manually.

Task-number: QTBUG-42674
Change-Id: Ia21e7ba9c17185796b0dd98c2c27d02566f2a701
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
---
 src/gui/text/qfontengine.cpp | 2 --
 src/gui/text/qharfbuzzng.cpp | 6 ++----
 src/gui/text/qtextengine.cpp | 2 --
 3 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp
index 52e10bd7171..0b517fbf29e 100644
--- a/src/gui/text/qfontengine.cpp
+++ b/src/gui/text/qfontengine.cpp
@@ -373,8 +373,6 @@ bool QFontEngine::supportsScript(QChar::Script script) const
                 if (!ret && script_tag_2 != HB_OT_TAG_DEFAULT_SCRIPT)
                     ret = hb_ot_layout_table_find_script(face, HB_OT_TAG_GSUB, HB_OT_TAG_DEFAULT_SCRIPT, &script_index);
             }
-
-            hb_face_destroy(face);
         }
         return ret;
     }
diff --git a/src/gui/text/qharfbuzzng.cpp b/src/gui/text/qharfbuzzng.cpp
index eb7bca19746..16c45e642b3 100644
--- a/src/gui/text/qharfbuzzng.cpp
+++ b/src/gui/text/qharfbuzzng.cpp
@@ -632,7 +632,7 @@ hb_face_t *hb_qt_face_get_for_engine(QFontEngine *fe)
         fe->face_destroy_func = _hb_qt_face_release;
     }
 
-    return hb_face_reference((hb_face_t *)fe->face_);
+    return (hb_face_t *)fe->face_;
 }
 
 
@@ -645,8 +645,6 @@ _hb_qt_font_create(QFontEngine *fe)
 
     hb_font_t *font = hb_font_create(face);
 
-    hb_face_destroy(face); // ref-ed in hb_qt_face_get_for_engine()
-
     if (Q_UNLIKELY(hb_font_is_immutable(font))) {
         hb_font_destroy(font);
         return NULL;
@@ -684,7 +682,7 @@ hb_font_t *hb_qt_font_get_for_engine(QFontEngine *fe)
         fe->font_destroy_func = _hb_qt_font_release;
     }
 
-    return hb_font_reference((hb_font_t *)fe->font_);
+    return (hb_font_t *)fe->font_;
 }
 
 QT_END_NAMESPACE
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 9fe1fd26e9f..d156124b984 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -1168,8 +1168,6 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st
             };
             const int num_features = 1;
             shapedOk = hb_shape_full(hb_font, buffer, features, num_features, 0);
-
-            hb_font_destroy(hb_font);
         }
         if (!shapedOk) {
             hb_buffer_destroy(buffer);
-- 
GitLab