Subject: Re: bug#58334: 29.0.50; ASAN heap use after free in gui_produce_glyphs

From: Gerd Möllmann <[email-masked]>
Date: Fri, 07 Oct 2022 14:01:49 +0200

Eli Zaretskii <[email-masked]> writes:

> So I would recommend to fix FACE_FROM_ID to re-generate the basic
> faces if needed, on the assumption that the cases where we have
> problems with using face ID are limited to basic faces.  If, after
> that, we will find cases with non-basic faces, I'd first look for more
> opportunities to use inhibit_free_realized_faces.

Sigh, I'd rather do something easy, and continue with what I wanted to
try out in the branch here.  It has only gpt one commit so far, in 3 or
4 days.

> One other thing is that inhibit_free_realized_faces is a boolean, so
> if nesting is possible, it cannot support such nesting; we'd need a
> reference count instead.

Yes, that's why I asked if we get by with something like this:

diff --git a/src/xdisp.c b/src/xdisp.c
index 9534e27843..fd94509fe4 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3179,7 +3179,8 @@ init_iterator (struct it *it, struct window *w,
      free realized faces now because they depend on face definitions
      that might have changed.  Don't free faces while there might be
      desired matrices pending which reference these faces.  */
-  if (!inhibit_free_realized_faces)
+  if (!inhibit_free_realized_faces
+      && !garbage_collection_inhibited)
     {
       if (face_change)
 	{

BTW, I've commented out the call to redisplay in nsterm.m
layoutSomething now in my branch.  Let's see what the effect is.  So far
I don't notice anything.