diff --git a/src/nvim/memline.c b/src/nvim/memline.c index f7f272f8dd..a0900faeab 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -510,6 +510,11 @@ void ml_open_file(buf_T *buf) // and creating it, another Vim creates the file. In that case the // creation will fail and we will use another directory. char *fname = findswapname(buf, &dirp, NULL, &found_existing_dir); + // autocmd may have freed mfp, grr! + if (buf->b_ml.ml_mfp != mfp) { + xfree(fname); + return; + } if (dirp == NULL) { break; // out of memory }