Subject: bug#76847: 31.0.50; feature/igc: Breakpoint 1, terminate_due_to_signal (sig=sig@entry=11, backtrace_limit=backtrace_limit@entry=40) at ./src/emacs.c:425

From: Gregor Zattler <[email-masked]>
Date: Sat, 08 Mar 2025 11:36:03 +0100

Hi Pip, Emacs developers,
* Pip Cet <[email-masked]> [2025-03-08; 09:58 GMT]:
> "Gregor Zattler via \"Bug reports for GNU Emacs, the Swiss army knife of text editors\"" <[email-masked]> writes:
> Thanks for the report! Just to confirm, you're using
> https://www.emacswiki.org/emacs/download/key-chord.el ?

no, I use
https://github.com/emacsorphanage/key-chord/
which is ~22 commits (most of them by
tarsius) ahead of the emacswiki version.

This is, what MELPA uses.

> I believe this is due to the very strange memory management in
> current_minor_maps.  This should have prevented the crash, but I can't
> properly test it right now.  It also changes behavior when running out
> of memory, but I don't think that's a real issue with MPS.
>
> diff --git a/src/keymap.c b/src/keymap.c
> index bc731c54ef0..43979bed905 100644
> --- a/src/keymap.c
> +++ b/src/keymap.c
> @@ -53,6 +53,7 @@
>  #include "intervals.h"
>  #include "keymap.h"
>  #include "window.h"
> +#include "igc.h"
>
>  /* Actually allocate storage for these variables.  */
>
> @@ -1588,26 +1589,42 @@ current_minor_maps (Lisp_Object **modeptr, Lisp_Object **mapptr)
>  		/* Use malloc here.  See the comment above this function.
>  		   Avoid realloc here; it causes spurious traps on GNU/Linux [KFS] */
>  		block_input ();
> +#ifdef HAVE_MPS
> +		newmodes = igc_xzalloc_ambig (allocsize);
> +#else
>  		newmodes = malloc (allocsize);
> +#endif
>  		if (newmodes)
>  		  {
>  		    if (cmm_modes)
>  		      {
>  			memcpy (newmodes, cmm_modes,
>  				cmm_size * sizeof cmm_modes[0]);
> +#ifdef HAVE_MPS
> +			igc_xfree (cmm_modes);
> +#else
>  			free (cmm_modes);
> +#endif
>  		      }
>  		    cmm_modes = newmodes;
>  		  }
>
> +#ifdef HAVE_MPS
> +		newmaps = igc_xzalloc_ambig (allocsize);
> +#else
>  		newmaps = malloc (allocsize);
> +#endif
>  		if (newmaps)
>  		  {
>  		    if (cmm_maps)
>  		      {
>  			memcpy (newmaps, cmm_maps,
>  				cmm_size * sizeof cmm_maps[0]);
> +#ifdef HAVE_MPS
> +			igc_xfree (cmm_maps);
> +#else
>  			free (cmm_maps);
> +#endif
>  		      }
>  		    cmm_maps = newmaps;
>  		  }
>

is this patch for me to test (I cannot
reproduce the problem)?

Ciao; Gregor
--
 -... --- .-. . -.. ..--.. ...-.-