Subject: bug#59794: 29.0.60; NSport segfaults when a fullscreen frame is being closed)

From: Po Lu <[email-masked]>
Date: Sun, 04 Dec 2022 19:59:34 +0800

Eli Zaretskii <[email-masked]> writes:

> Why, cannot you access debbugs?

debbugs-browse-ephemeral-emacs-bug-group only included your reply to
this bug, and not the patch you replied to.  That happens once in a
while for me.

> Anyway, attached below.
>
>>>From 8ea35a8099f34f482d090ea8068e89f52dcd29ac Mon Sep 17 00:00:00 2001
> From: Kai Ma <[email-masked]>
> Date: Sat, 3 Dec 2022 18:17:26 +0800
> Subject: [PATCH] Prevent a segfault when deleting a fullscreen frame on
>  NextStep.
>
> * nsterm.m ([EmacsView resetCursorRects:]): Be defensive when
> accessing FRAME_OUTPUT_DATA.
> ---
>  src/nsterm.m | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/src/nsterm.m b/src/nsterm.m
> index 507f2a9e7d..c09f743ec7 100644
> --- a/src/nsterm.m
> +++ b/src/nsterm.m
> @@ -6703,8 +6703,16 @@ - (BOOL)acceptsFirstResponder
>  
>  - (void)resetCursorRects
>  {
> -  NSRect visible = [self visibleRect];
> -  NSCursor *currentCursor = FRAME_POINTER_TYPE (emacsframe);
> +  NSRect visible;
> +  NSCursor *currentCursor;
> +
> +  /* On macOS 13, [resetCursorRects:] could be called even after the
> +     window is closed. */
> +  if (! emacsframe || ! FRAME_OUTPUT_DATA (emacsframe))
> +    return;
> +
> +  visible = [self visibleRect];
> +  currentCursor = FRAME_POINTER_TYPE (emacsframe);
>    NSTRACE ("[EmacsView resetCursorRects]");
>  
>    if (currentCursor == nil)

Thanks.  I'm fine with installing this on the release branch, but the
comment should be modified to say:

  [resetCursorRects:] can be called from the event loop after the frame
  is deleted.  When this happens, emacsframe is NULL.  This means there
  is an underlying leak of the EmacsView object!

also, perhaps it should be omitted on master, at least until before
Emacs 30 is released, to motivate other (hopefully more knowledgeable)
people to provide the necessary information to fix it.