From: Pip Cet Date: Sat, 10 Aug 2024 16:57:49 +0000 (+0000) Subject: Make ftcrfont_close idempotent X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d3e862e2814f020185fc36dee9c9de863b4cbb66;p=emacs.git Make ftcrfont_close idempotent This prevents crashes when running code like: (let ((font (open-font (find-font (font-spec ...))))) (close-font font) (close-font font)) * src/ftcrfont.c (ftcrfont_close): Make sure the function can be run several times in a row without crashing. (cherry picked from commit 1a38936299d3c93767e4b542ccde990ea08379e3) --- diff --git a/src/ftcrfont.c b/src/ftcrfont.c index 5ee375c782b..3700154e44a 100644 --- a/src/ftcrfont.c +++ b/src/ftcrfont.c @@ -344,12 +344,20 @@ ftcrfont_close (struct font *font) ftcrfont_info->hb_font = NULL; } #endif - for (int i = 0; i < ftcrfont_info->metrics_nrows; i++) - if (ftcrfont_info->metrics[i]) - xfree (ftcrfont_info->metrics[i]); if (ftcrfont_info->metrics) - xfree (ftcrfont_info->metrics); - cairo_scaled_font_destroy (ftcrfont_info->cr_scaled_font); + { + for (int i = 0; i < ftcrfont_info->metrics_nrows; i++) + if (ftcrfont_info->metrics[i]) + xfree (ftcrfont_info->metrics[i]); + if (ftcrfont_info->metrics) + xfree (ftcrfont_info->metrics); + ftcrfont_info->metrics = NULL; + } + if (ftcrfont_info->cr_scaled_font) + { + cairo_scaled_font_destroy (ftcrfont_info->cr_scaled_font); + ftcrfont_info->cr_scaled_font = NULL; + } unblock_input (); }