aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2020-10-26 18:14:32 +0200
committerEli Zaretskii2020-10-26 18:14:32 +0200
commit634bbb61f2f1b3e0fdf830f58a7ec7e39ea5a14f (patch)
tree529545df5e1424558c06b2224a54836929b6a5e7 /src
parentcdb3c9d662c772ce25ea4d803eccd2c9e6a6ae99 (diff)
downloademacs-634bbb61f2f1b3e0fdf830f58a7ec7e39ea5a14f.tar.gz
emacs-634bbb61f2f1b3e0fdf830f58a7ec7e39ea5a14f.zip
Avoid segfaults due to using fonts that were closed
* src/composite.c (composition_gstring_cache_clear_font): New function. * src/composite.h (composition_gstring_cache_clear_font): Add prototype. * src/font.c (font_clear_cache): When we are about to close a font, remove from the gstring cache any lgstring that uses this font. (Bug#42943)
Diffstat (limited to 'src')
-rw-r--r--src/composite.c21
-rw-r--r--src/composite.h2
-rw-r--r--src/font.c5
3 files changed, 28 insertions, 0 deletions
diff --git a/src/composite.c b/src/composite.c
index 90f8536b2de..66c1e86aae1 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -677,6 +677,27 @@ composition_gstring_from_id (ptrdiff_t id)
677 return HASH_VALUE (h, id); 677 return HASH_VALUE (h, id);
678} 678}
679 679
680/* Remove from the composition hash table every lgstring that
681 references the given FONT_OBJECT. */
682void
683composition_gstring_cache_clear_font (Lisp_Object font_object)
684{
685 struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
686
687 for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
688 {
689 Lisp_Object k = HASH_KEY (h, i);
690
691 if (!EQ (k, Qunbound))
692 {
693 Lisp_Object gstring = HASH_VALUE (h, i);
694
695 if (EQ (LGSTRING_FONT (gstring), font_object))
696 hash_remove_from_table (h, k);
697 }
698 }
699}
700
680DEFUN ("clear-composition-cache", Fclear_composition_cache, 701DEFUN ("clear-composition-cache", Fclear_composition_cache,
681 Sclear_composition_cache, 0, 0, 0, 702 Sclear_composition_cache, 0, 0, 0,
682 doc: /* Internal use only. 703 doc: /* Internal use only.
diff --git a/src/composite.h b/src/composite.h
index d39fdbaae05..bdf63fed10e 100644
--- a/src/composite.h
+++ b/src/composite.h
@@ -332,6 +332,8 @@ extern int composition_update_it (struct composition_it *,
332extern ptrdiff_t composition_adjust_point (ptrdiff_t, ptrdiff_t); 332extern ptrdiff_t composition_adjust_point (ptrdiff_t, ptrdiff_t);
333extern Lisp_Object composition_gstring_lookup_cache (Lisp_Object); 333extern Lisp_Object composition_gstring_lookup_cache (Lisp_Object);
334 334
335extern void composition_gstring_cache_clear_font (Lisp_Object);
336
335INLINE_HEADER_END 337INLINE_HEADER_END
336 338
337#endif /* not EMACS_COMPOSITE_H */ 339#endif /* not EMACS_COMPOSITE_H */
diff --git a/src/font.c b/src/font.c
index f7c4c816b5d..8dbf8cb8999 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2645,6 +2645,11 @@ font_clear_cache (struct frame *f, Lisp_Object cache,
2645 if (! NILP (AREF (val, FONT_TYPE_INDEX))) 2645 if (! NILP (AREF (val, FONT_TYPE_INDEX)))
2646 { 2646 {
2647 eassert (font && driver == font->driver); 2647 eassert (font && driver == font->driver);
2648 /* We are going to close the font, so make
2649 sure we don't have any lgstrings lying
2650 around in lgstring cache that reference
2651 the font. */
2652 composition_gstring_cache_clear_font (val);
2648 driver->close_font (font); 2653 driver->close_font (font);
2649 } 2654 }
2650 } 2655 }