Mercurial > vim
comparison src/ex_docmd.c @ 18406:fa6efc49d71f v8.1.2197
patch 8.1.2197: ExitPre autocommand may cause accessing freed memory
Commit: https://github.com/vim/vim/commit/34ba06b6e6f94bb46062e6c85dbfdcbb0d255ada
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 20 22:27:10 2019 +0200
patch 8.1.2197: ExitPre autocommand may cause accessing freed memory
Problem: ExitPre autocommand may cause accessing freed memory.
Solution: Check the window pointer is still valid. (closes https://github.com/vim/vim/issues/5093)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 20 Oct 2019 22:30:03 +0200 |
parents | 527b7084c556 |
children | baf890fa1621 |
comparison
equal
deleted
inserted
replaced
18405:ef35dddb7189 | 18406:fa6efc49d71f |
---|---|
4815 static int | 4815 static int |
4816 before_quit_autocmds(win_T *wp, int quit_all, int forceit) | 4816 before_quit_autocmds(win_T *wp, int quit_all, int forceit) |
4817 { | 4817 { |
4818 apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, wp->w_buffer); | 4818 apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, wp->w_buffer); |
4819 | 4819 |
4820 /* Bail out when autocommands closed the window. | 4820 // Bail out when autocommands closed the window. |
4821 * Refuse to quit when the buffer in the last window is being closed (can | 4821 // Refuse to quit when the buffer in the last window is being closed (can |
4822 * only happen in autocommands). */ | 4822 // only happen in autocommands). |
4823 if (!win_valid(wp) | 4823 if (!win_valid(wp) |
4824 || curbuf_locked() | 4824 || curbuf_locked() |
4825 || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0)) | 4825 || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0)) |
4826 return TRUE; | 4826 return TRUE; |
4827 | 4827 |
4828 if (quit_all || (check_more(FALSE, forceit) == OK && only_one_window())) | 4828 if (quit_all || (check_more(FALSE, forceit) == OK && only_one_window())) |
4829 { | 4829 { |
4830 apply_autocmds(EVENT_EXITPRE, NULL, NULL, FALSE, curbuf); | 4830 apply_autocmds(EVENT_EXITPRE, NULL, NULL, FALSE, curbuf); |
4831 /* Refuse to quit when locked or when the buffer in the last window is | 4831 // Refuse to quit when locked or when the window was closed or the |
4832 * being closed (can only happen in autocommands). */ | 4832 // buffer in the last window is being closed (can only happen in |
4833 if (curbuf_locked() | 4833 // autocommands). |
4834 if (!win_valid(wp) || curbuf_locked() | |
4834 || (curbuf->b_nwindows == 1 && curbuf->b_locked > 0)) | 4835 || (curbuf->b_nwindows == 1 && curbuf->b_locked > 0)) |
4835 return TRUE; | 4836 return TRUE; |
4836 } | 4837 } |
4837 | 4838 |
4838 return FALSE; | 4839 return FALSE; |