Blame SOURCES/7.4.022

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