summaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2014-04-06 20:45:43 +0200
committerBram Moolenaar <Bram@vim.org>2014-04-06 20:45:43 +0200
commit4c7ab1bb5722de662db04550b74256671f20c4a2 (patch)
tree9fc51404bf8d87a9aa99df7ff30f18617f03513b /src/buffer.c
parent75b8156a445fb4788dc3d1946764af30b5c50ac4 (diff)
updated for version 7.4.251v7.4.251
Problem: Crash when BufAdd autocommand wipes out the buffer. Solution: Check for buffer to still be valid. Postpone freeing the buffer structure. (Hirohito Higashi)
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/buffer.c b/src/buffer.c
index c703465e3f..3506dbb9a5 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -676,8 +676,16 @@ free_buffer(buf)
#endif
#ifdef FEAT_AUTOCMD
aubuflocal_remove(buf);
+ if (autocmd_busy)
+ {
+ /* Do not free the buffer structure while autocommands are executing,
+ * it's still needed. Free it when autocmd_busy is reset. */
+ buf->b_next = au_pending_free_buf;
+ au_pending_free_buf = buf;
+ }
+ else
#endif
- vim_free(buf);
+ vim_free(buf);
}
/*
@@ -1681,7 +1689,11 @@ buflist_new(ffname, sfname, lnum, flags)
buf->b_p_bl = TRUE;
#ifdef FEAT_AUTOCMD
if (!(flags & BLN_DUMMY))
+ {
apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf);
+ if (!buf_valid(buf))
+ return NULL;
+ }
#endif
}
return buf;
@@ -1857,8 +1869,14 @@ buflist_new(ffname, sfname, lnum, flags)
if (!(flags & BLN_DUMMY))
{
apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf);
+ if (!buf_valid(buf))
+ return NULL;
if (flags & BLN_LISTED)
+ {
apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf);
+ if (!buf_valid(buf))
+ return NULL;
+ }
# ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
return NULL;