diff src/buffer.c @ 13720:7d2039b2ecc8 v8.0.1732

patch 8.0.1732: crash when terminal API call deletes the buffer commit https://github.com/vim/vim/commit/a997b45c7e350ea5b378ca0c52ed3d4cc610975c Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 17 23:24:06 2018 +0200 patch 8.0.1732: crash when terminal API call deletes the buffer Problem: Crash when terminal API call deletes the buffer. Solution: Lock the buffer while calling a function. (closes https://github.com/vim/vim/issues/2813)
author Christian Brabandt <cb@256bit.org>
date Tue, 17 Apr 2018 23:30:07 +0200
parents cec5137d5332
children 3be5e8306a3e
line wrap: on
line diff
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -417,6 +417,8 @@ buf_hashtab_remove(buf_T *buf)
 	hash_remove(&buf_hashtab, hi);
 }
 
+static char *e_buflocked = N_("E937: Attempt to delete a buffer that is in use");
+
 /*
  * Close the link to a buffer.
  * "action" is used when there is no longer a window for the buffer.
@@ -476,8 +478,15 @@ close_buffer(
 	if (term_job_running(buf->b_term))
 	{
 	    if (wipe_buf || unload_buf)
+	    {
+		if (buf->b_locked)
+		{
+		    EMSG(_(e_buflocked));
+		    return;
+		}
 		/* Wiping out or unloading a terminal buffer kills the job. */
 		free_terminal(buf);
+	    }
 	    else
 	    {
 		/* The job keeps running, hide the buffer. */
@@ -499,7 +508,7 @@ close_buffer(
      * halfway a command that relies on it). Unloading is allowed. */
     if (buf->b_locked > 0 && (del_buf || wipe_buf))
     {
-	EMSG(_("E937: Attempt to delete a buffer that is in use"));
+	EMSG(_(e_buflocked));
 	return;
     }
 
@@ -1356,6 +1365,12 @@ do_buffer(
 	int	forward;
 	bufref_T bufref;
 
+	if (buf->b_locked)
+	{
+	    EMSG(_(e_buflocked));
+	    return FAIL;
+	}
+
 	set_bufref(&bufref, buf);
 
 	/* When unloading or deleting a buffer that's already unloaded and