Subject: Re: bug#14986: Latest Emacs trunk crashes when changing Ispell dictionary

From: Eli Zaretskii <[email-masked]>
Date: Tue, 30 Jul 2013 23:01:28 +0300

> From: "Sebastien Vauban" <[email-masked]>
> Cc: [email-masked]
> Date: Tue, 30 Jul 2013 21:46:55 +0200
> 
> #1  0x011ea214 in emacs_abort () at c:/msys/home/dani/emacs/trunk/src/w32fns.c:8030
> #2  0x010db2e8 in terminate_due_to_signal (sig=22, backtrace_limit=2147483647) at c:/msys/home/dani/emacs/trunk/src/emacs.c:369
> #3  0x011503d5 in die (msg=0x147f8a2 <baud_convert+482> "errno != EBADF || fd < 0", file=0x147f708 <baud_convert+72> "c:/msys/home/dani/emacs/trunk/src/sysdep.c",
>     line=2272) at c:/msys/home/dani/emacs/trunk/src/alloc.c:6558
> #4  0x010ff747 in emacs_close (fd=2147483647) at c:/msys/home/dani/emacs/trunk/src/sysdep.c:2272
> #5  0x011c0654 in create_temp_file (nargs=12, args=0x88e264) at c:/msys/home/dani/emacs/trunk/src/callproc.c:1027
> #6  0x011c0965 in Fcall_process_region (nargs=12, args=0x88e264) at c:/msys/home/dani/emacs/trunk/src/callproc.c:1118

Thanks.

Paul, I'm afraid that the assumption in create_temp_file, viz.:

      errno = EEXIST;
      mktemp (tempfile);
      /* INT_MAX denotes success, because close (INT_MAX) does nothing.  */
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      fd = *tempfile ? INT_MAX : -1;

and this code in emacs_close:

  int
  emacs_close (int fd)
  {
    while (1)
      {
	int r = posix_close (fd, POSIX_CLOSE_RESTART);
	if (r == 0)
	  return r;
	if (!POSIX_CLOSE_RESTART || errno != EINTR)
	  {
	    eassert (errno != EBADF || fd < 0);
	    return errno == EINPROGRESS ? 0 : r;
	  }
      }

will not work on Windows, because closing a file descriptor of INT_MAX
will most certainly produce EBADF on Windows.

Why is this trickery needed for platforms that use mktemp?