@@ -120,11 +120,20 @@ void PangoFontInfo::SoftInitFontConfig() {
120
120
PangoFontMap* PangoFontInfo::get_font_map () {
121
121
PangoFontMap* font_map =
122
122
pango_cairo_font_map_new_for_font_type (CAIRO_FONT_TYPE_FT);
123
- if (!font_map) // cairo withtout support of Freetype?
123
+ if (!font_map) // cairo without support of Freetype?
124
124
font_map = pango_cairo_font_map_get_default ();
125
125
return font_map;
126
126
}
127
127
128
+ // PangoFontMap created with pango_cairo_font_map_new_for_font_type should() be freed
129
+ // PangoFontMap created with pango_cairo_font_map_get_default() must not be freed
130
+ void PangoFontInfo::free_font_map (PangoFontMap* font_map) {
131
+ if (pango_cairo_font_map_get_font_type ((PangoCairoFontMap*)(font_map)) == CAIRO_FONT_TYPE_FT) {
132
+ g_object_unref (font_map);
133
+ font_map = nullptr ;
134
+ }
135
+ }
136
+
128
137
// Re-initializes font config, whether or not already initialized.
129
138
// If already initialized, any existing cache is deleted, just to be sure.
130
139
/* static */
@@ -174,6 +183,7 @@ static void ListFontFamilies(PangoFontFamily*** families,
174
183
PangoFontMap* font_map = PangoFontInfo::get_font_map ();
175
184
DISABLE_HEAP_LEAK_CHECK;
176
185
pango_font_map_list_families (font_map, families, n_families);
186
+ PangoFontInfo::free_font_map (font_map);
177
187
}
178
188
179
189
bool PangoFontInfo::ParseFontDescription (const PangoFontDescription *desc) {
@@ -220,6 +230,7 @@ PangoFont* PangoFontInfo::ToPangoFont() const {
220
230
font = pango_font_map_load_font (font_map, context, desc_);
221
231
}
222
232
g_object_unref (context);
233
+ PangoFontInfo::free_font_map (font_map);
223
234
return font;
224
235
}
225
236
@@ -236,6 +247,8 @@ bool PangoFontInfo::CoversUTF8Text(const char* utf8_text, int byte_length) const
236
247
int len = it.get_utf8 (tmp);
237
248
tmp[len] = ' \0 ' ;
238
249
tlog (2 , " '%s' (U+%x) not covered by font\n " , tmp, *it);
250
+ pango_coverage_unref (coverage);
251
+ g_object_unref (font);
239
252
return false ;
240
253
}
241
254
}
@@ -329,6 +342,7 @@ bool PangoFontInfo::GetSpacingProperties(const std::string& utf8_char,
329
342
if (!glyph_index) {
330
343
// Glyph for given unicode character doesn't exist in font.
331
344
g_object_unref (font);
345
+ font = nullptr ;
332
346
return false ;
333
347
}
334
348
// Find the ink glyph extents for the glyph
@@ -346,6 +360,7 @@ bool PangoFontInfo::GetSpacingProperties(const std::string& utf8_char,
346
360
*x_bearing = min_bearing;
347
361
*x_advance = total_advance;
348
362
g_object_unref (font);
363
+ font = nullptr ;
349
364
return true ;
350
365
}
351
366
@@ -465,6 +480,7 @@ bool PangoFontInfo::CanRenderString(const char* utf8_word, int len,
465
480
pango_layout_iter_free (run_iter);
466
481
g_object_unref (context);
467
482
g_object_unref (layout);
483
+ free_font_map (font_map);
468
484
if (bad_glyph && graphemes) graphemes->clear ();
469
485
return !bad_glyph;
470
486
}
@@ -499,6 +515,7 @@ bool FontUtils::IsAvailableFont(const char* input_query_desc,
499
515
selected_font = pango_font_map_load_font (font_map, context, desc);
500
516
}
501
517
g_object_unref (context);
518
+ PangoFontInfo::free_font_map (font_map);
502
519
}
503
520
if (selected_font == nullptr ) {
504
521
pango_font_description_free (desc);
0 commit comments