comparison src/window.c @ 28429:aa9720c76412 v8.2.4739

patch 8.2.4739: accessing freed memory after WinScrolled autocmd event Commit: https://github.com/vim/vim/commit/d58862d18f091d3c14fa3647e724ef7eea1ecefa Author: zeertzjq <zeertzjq@outlook.com> Date: Tue Apr 12 11:32:48 2022 +0100 patch 8.2.4739: accessing freed memory after WinScrolled autocmd event Problem: Accessing freed memory after WinScrolled autocmd event. Solution: Check the window pointer is still valid. (closes https://github.com/vim/vim/issues/10156) Remove the argument from may_trigger_winscrolled().
author Bram Moolenaar <Bram@vim.org>
date Tue, 12 Apr 2022 12:45:04 +0200
parents e466fdbe0699
children 264fa41e6704
comparison
equal deleted inserted replaced
28428:eb08141a60cb 28429:aa9720c76412
2782 vim_snprintf((char *)winid, sizeof(winid), "%d", win->w_id); 2782 vim_snprintf((char *)winid, sizeof(winid), "%d", win->w_id);
2783 apply_autocmds(EVENT_WINCLOSED, winid, winid, FALSE, win->w_buffer); 2783 apply_autocmds(EVENT_WINCLOSED, winid, winid, FALSE, win->w_buffer);
2784 recursive = FALSE; 2784 recursive = FALSE;
2785 } 2785 }
2786 2786
2787 /*
2788 * Trigger WinScrolled for "curwin" if needed.
2789 */
2787 void 2790 void
2788 may_trigger_winscrolled(win_T *wp) 2791 may_trigger_winscrolled(void)
2789 { 2792 {
2793 win_T *wp = curwin;
2790 static int recursive = FALSE; 2794 static int recursive = FALSE;
2791 char_u winid[NUMBUFLEN]; 2795 char_u winid[NUMBUFLEN];
2792 2796
2793 if (recursive || !has_winscrolled()) 2797 if (recursive || !has_winscrolled())
2794 return; 2798 return;
2802 2806
2803 recursive = TRUE; 2807 recursive = TRUE;
2804 apply_autocmds(EVENT_WINSCROLLED, winid, winid, FALSE, wp->w_buffer); 2808 apply_autocmds(EVENT_WINSCROLLED, winid, winid, FALSE, wp->w_buffer);
2805 recursive = FALSE; 2809 recursive = FALSE;
2806 2810
2807 wp->w_last_topline = wp->w_topline; 2811 // an autocmd may close the window, "wp" may be invalid now
2808 wp->w_last_leftcol = wp->w_leftcol; 2812 if (win_valid_any_tab(wp))
2809 wp->w_last_width = wp->w_width; 2813 {
2810 wp->w_last_height = wp->w_height; 2814 wp->w_last_topline = wp->w_topline;
2815 wp->w_last_leftcol = wp->w_leftcol;
2816 wp->w_last_width = wp->w_width;
2817 wp->w_last_height = wp->w_height;
2818 }
2811 } 2819 }
2812 } 2820 }
2813 2821
2814 /* 2822 /*
2815 * Close window "win" in tab page "tp", which is not the current tab page. 2823 * Close window "win" in tab page "tp", which is not the current tab page.