Mercurial > vim
diff src/buffer.c @ 5816:29eb4c2a33ac v7.4.251
updated for version 7.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)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sun, 06 Apr 2014 20:45:43 +0200 |
parents | 50dbef5e774a |
children | 373204662d82 |
line wrap: on
line diff
--- a/src/buffer.c +++ b/src/buffer.c @@ -676,8 +676,16 @@ free_buffer(buf) #endif #ifdef FEAT_AUTOCMD aubuflocal_remove(buf); -#endif - vim_free(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); } /* @@ -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;