1fa1ff
To: vim_dev@googlegroups.com
1fa1ff
Subject: Patch 7.4.022
1fa1ff
Fcc: outbox
1fa1ff
From: Bram Moolenaar <Bram@moolenaar.net>
1fa1ff
Mime-Version: 1.0
1fa1ff
Content-Type: text/plain; charset=UTF-8
1fa1ff
Content-Transfer-Encoding: 8bit
1fa1ff
------------
1fa1ff
1fa1ff
Patch 7.4.022
1fa1ff
Problem:    Deadlock while exiting, because of allocating memory.
1fa1ff
Solution:   Do not use gettext() in deathtrap(). (James McCoy)
1fa1ff
Files:	    src/os_unix.c, src/misc1.c
1fa1ff
1fa1ff
1fa1ff
*** ../vim-7.4.021/src/os_unix.c	2013-07-03 16:32:32.000000000 +0200
1fa1ff
--- src/os_unix.c	2013-09-05 21:40:06.000000000 +0200
1fa1ff
***************
1fa1ff
*** 957,964 ****
1fa1ff
  
1fa1ff
  /*
1fa1ff
   * This function handles deadly signals.
1fa1ff
!  * It tries to preserve any swap file and exit properly.
1fa1ff
   * (partly from Elvis).
1fa1ff
   */
1fa1ff
      static RETSIGTYPE
1fa1ff
  deathtrap SIGDEFARG(sigarg)
1fa1ff
--- 957,966 ----
1fa1ff
  
1fa1ff
  /*
1fa1ff
   * This function handles deadly signals.
1fa1ff
!  * It tries to preserve any swap files and exit properly.
1fa1ff
   * (partly from Elvis).
1fa1ff
+  * NOTE: Avoid unsafe functions, such as allocating memory, they can result in
1fa1ff
+  * a deadlock.
1fa1ff
   */
1fa1ff
      static RETSIGTYPE
1fa1ff
  deathtrap SIGDEFARG(sigarg)
1fa1ff
***************
1fa1ff
*** 1090,1107 ****
1fa1ff
      }
1fa1ff
      if (entered == 2)
1fa1ff
      {
1fa1ff
! 	OUT_STR(_("Vim: Double signal, exiting\n"));
1fa1ff
  	out_flush();
1fa1ff
  	getout(1);
1fa1ff
      }
1fa1ff
  
1fa1ff
  #ifdef SIGHASARG
1fa1ff
!     sprintf((char *)IObuff, _("Vim: Caught deadly signal %s\n"),
1fa1ff
  							 signal_info[i].name);
1fa1ff
  #else
1fa1ff
!     sprintf((char *)IObuff, _("Vim: Caught deadly signal\n"));
1fa1ff
  #endif
1fa1ff
!     preserve_exit();		    /* preserve files and exit */
1fa1ff
  
1fa1ff
  #ifdef NBDEBUG
1fa1ff
      reset_signals();
1fa1ff
--- 1092,1114 ----
1fa1ff
      }
1fa1ff
      if (entered == 2)
1fa1ff
      {
1fa1ff
! 	/* No translation, it may call malloc(). */
1fa1ff
! 	OUT_STR("Vim: Double signal, exiting\n");
1fa1ff
  	out_flush();
1fa1ff
  	getout(1);
1fa1ff
      }
1fa1ff
  
1fa1ff
+     /* No translation, it may call malloc(). */
1fa1ff
  #ifdef SIGHASARG
1fa1ff
!     sprintf((char *)IObuff, "Vim: Caught deadly signal %s\n",
1fa1ff
  							 signal_info[i].name);
1fa1ff
  #else
1fa1ff
!     sprintf((char *)IObuff, "Vim: Caught deadly signal\n");
1fa1ff
  #endif
1fa1ff
! 
1fa1ff
!     /* Preserve files and exit.  This sets the really_exiting flag to prevent
1fa1ff
!      * calling free(). */
1fa1ff
!     preserve_exit();
1fa1ff
  
1fa1ff
  #ifdef NBDEBUG
1fa1ff
      reset_signals();
1fa1ff
*** ../vim-7.4.021/src/misc1.c	2013-08-03 17:29:33.000000000 +0200
1fa1ff
--- src/misc1.c	2013-09-05 21:34:04.000000000 +0200
1fa1ff
***************
1fa1ff
*** 9174,9179 ****
1fa1ff
--- 9174,9181 ----
1fa1ff
  /*
1fa1ff
   * Preserve files and exit.
1fa1ff
   * When called IObuff must contain a message.
1fa1ff
+  * NOTE: This may be called from deathtrap() in a signal handler, avoid unsafe
1fa1ff
+  * functions, such as allocating memory.
1fa1ff
   */
1fa1ff
      void
1fa1ff
  preserve_exit()
1fa1ff
***************
1fa1ff
*** 9196,9202 ****
1fa1ff
      {
1fa1ff
  	if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL)
1fa1ff
  	{
1fa1ff
! 	    OUT_STR(_("Vim: preserving files...\n"));
1fa1ff
  	    screen_start();	    /* don't know where cursor is now */
1fa1ff
  	    out_flush();
1fa1ff
  	    ml_sync_all(FALSE, FALSE);	/* preserve all swap files */
1fa1ff
--- 9198,9204 ----
1fa1ff
      {
1fa1ff
  	if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL)
1fa1ff
  	{
1fa1ff
! 	    OUT_STR("Vim: preserving files...\n");
1fa1ff
  	    screen_start();	    /* don't know where cursor is now */
1fa1ff
  	    out_flush();
1fa1ff
  	    ml_sync_all(FALSE, FALSE);	/* preserve all swap files */
1fa1ff
***************
1fa1ff
*** 9206,9212 ****
1fa1ff
  
1fa1ff
      ml_close_all(FALSE);	    /* close all memfiles, without deleting */
1fa1ff
  
1fa1ff
!     OUT_STR(_("Vim: Finished.\n"));
1fa1ff
  
1fa1ff
      getout(1);
1fa1ff
  }
1fa1ff
--- 9208,9214 ----
1fa1ff
  
1fa1ff
      ml_close_all(FALSE);	    /* close all memfiles, without deleting */
1fa1ff
  
1fa1ff
!     OUT_STR("Vim: Finished.\n");
1fa1ff
  
1fa1ff
      getout(1);
1fa1ff
  }
1fa1ff
*** ../vim-7.4.021/src/version.c	2013-09-05 21:15:38.000000000 +0200
1fa1ff
--- src/version.c	2013-09-05 21:30:18.000000000 +0200
1fa1ff
***************
1fa1ff
*** 740,741 ****
1fa1ff
--- 740,743 ----
1fa1ff
  {   /* Add new patch number below this line */
1fa1ff
+ /**/
1fa1ff
+     22,
1fa1ff
  /**/
1fa1ff
1fa1ff
-- 
1fa1ff
hundred-and-one symptoms of being an internet addict:
1fa1ff
175. You send yourself e-mail before you go to bed to remind you
1fa1ff
     what to do when you wake up.
1fa1ff
1fa1ff
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
1fa1ff
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
1fa1ff
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
1fa1ff
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///