Subject: Re: bug#20802: Segfault when showing non-GTK+ tooltip

From: Eli Zaretskii <[email-masked]>
Date: Thu, 18 Jun 2015 18:53:39 +0300

> Date: Thu, 18 Jun 2015 15:37:20 +0200
> From: martin rudalics <[email-masked]>
> CC: [email-masked], [email-masked]
> 
>  > Why can't we simply move the code that frees the image cache to
>  > delete_terminal?  There's only one image cache for each terminal, and
>  > it's shared by all frames on that terminal, right?  And we call
>  > delete-terminal when we delete the last frame on the terminal, right?
> 
> ‘delete-terminal’ can run into precisely the same problem I described in
> my previous scenario.  IMHO we have to give up the idea of using
> refcounts to tell whether a frame might still use some object - they are
> not up to this task.

These are 2 different issues.

Do you agree that there's no need to decide whether we should free the
image cache while deleting a frame, and instead do that when we delete
a terminal?  If you agree, we should move the code that frees the
image cache there.

If, in addition, you are saying that we will sometimes delete a
terminal when it still has live frames, then we could simply count the
frames on a terminal instead of using a refcount.  Something like this
(we already have similar code in delete_frame):

      count = 0;
      FOR_EACH_FRAME (tail, frame1)
	if (FRAME_TERMINAL (XFRAME (frame)) == FRAME_TERMINAL (XFRAME (frame1)))
	  count++;