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