Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] malloc inside signal handler



On Fri, Jul 30, 2021 at 06:33:08PM -0700, Bart Schaefer wrote:
> Under what circumstances are you generating this error?

I had the crash with the following command:

    zsh -c ". hashes.zsh; print ~dir"

that was being executed inside $TERMINAL -e so that explains SIGWINCH.

(hashes.zsh contains a few hash -d lines.)

Unfortunately, I could not find any way to reproduce this again, even
though I call it a few hundred times a day.

However, looking at the stack trace it seems straightforward (for me)
what's going on:

shingetline() calls winch_unblock() and dont_queue_signals() so fgetc()
can be interrupted at any time.

$ gdb zsh -ex 'b input.c:153' -ex 'r' -ex 'b adjustwinsize' -ex 'signal SIGWINCH' -ex 'bt'

Just to make sure, it confirms that SIGWINCH can be handled around
fgetc(), maybe during a memory allocation inside it so if
adjustwinsize() also uses malloc() that can be fatal.

-- 
zsugabubus




Messages sorted by: Reverse Date, Date, Thread, Author