comparison src/buffer.c @ 27507:b8a5de86e9d1 v8.2.4281

patch 8.2.4281: using freed memory with :lopen and :bwipe Commit: https://github.com/vim/vim/commit/9b4a80a66544f2782040b641498754bcb5b8d461 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 1 13:54:17 2022 +0000 patch 8.2.4281: using freed memory with :lopen and :bwipe Problem: Using freed memory with :lopen and :bwipe. Solution: Do not use a wiped out buffer.
author Bram Moolenaar <Bram@vim.org>
date Tue, 01 Feb 2022 15:00:05 +0100
parents 41e0dcf38521
children cb46dd386990
comparison
equal deleted inserted replaced
27506:68e8643bae78 27507:b8a5de86e9d1
1704 #ifdef FEAT_SYN_HL 1704 #ifdef FEAT_SYN_HL
1705 long old_tw = curbuf->b_p_tw; 1705 long old_tw = curbuf->b_p_tw;
1706 #endif 1706 #endif
1707 bufref_T newbufref; 1707 bufref_T newbufref;
1708 bufref_T prevbufref; 1708 bufref_T prevbufref;
1709 int valid;
1709 1710
1710 setpcmark(); 1711 setpcmark();
1711 if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) 1712 if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0)
1712 curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file 1713 curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file
1713 buflist_altfpos(curwin); // remember curpos 1714 buflist_altfpos(curwin); // remember curpos
1761 } 1762 }
1762 } 1763 }
1763 // An autocommand may have deleted "buf", already entered it (e.g., when 1764 // An autocommand may have deleted "buf", already entered it (e.g., when
1764 // it did ":bunload") or aborted the script processing. 1765 // it did ":bunload") or aborted the script processing.
1765 // If curwin->w_buffer is null, enter_buffer() will make it valid again 1766 // If curwin->w_buffer is null, enter_buffer() will make it valid again
1766 if ((buf_valid(buf) && buf != curbuf 1767 valid = buf_valid(buf);
1768 if ((valid && buf != curbuf
1767 #ifdef FEAT_EVAL 1769 #ifdef FEAT_EVAL
1768 && !aborting() 1770 && !aborting()
1769 #endif 1771 #endif
1770 ) || curwin->w_buffer == NULL) 1772 ) || curwin->w_buffer == NULL)
1771 { 1773 {
1772 enter_buffer(buf); 1774 // If the buffer is not valid but curwin->w_buffer is NULL we must
1775 // enter some buffer. Using the last one is hopefully OK.
1776 if (!valid)
1777 enter_buffer(lastbuf);
1778 else
1779 enter_buffer(buf);
1773 #ifdef FEAT_SYN_HL 1780 #ifdef FEAT_SYN_HL
1774 if (old_tw != curbuf->b_p_tw) 1781 if (old_tw != curbuf->b_p_tw)
1775 check_colorcolumn(curwin); 1782 check_colorcolumn(curwin);
1776 #endif 1783 #endif
1777 } 1784 }
2286 clear_string_option(&buf->b_p_isk); 2293 clear_string_option(&buf->b_p_isk);
2287 #ifdef FEAT_VARTABS 2294 #ifdef FEAT_VARTABS
2288 clear_string_option(&buf->b_p_vsts); 2295 clear_string_option(&buf->b_p_vsts);
2289 vim_free(buf->b_p_vsts_nopaste); 2296 vim_free(buf->b_p_vsts_nopaste);
2290 buf->b_p_vsts_nopaste = NULL; 2297 buf->b_p_vsts_nopaste = NULL;
2291 vim_free(buf->b_p_vsts_array); 2298 VIM_CLEAR(buf->b_p_vsts_array);
2292 buf->b_p_vsts_array = NULL;
2293 clear_string_option(&buf->b_p_vts); 2299 clear_string_option(&buf->b_p_vts);
2294 VIM_CLEAR(buf->b_p_vts_array); 2300 VIM_CLEAR(buf->b_p_vts_array);
2295 #endif 2301 #endif
2296 #ifdef FEAT_KEYMAP 2302 #ifdef FEAT_KEYMAP
2297 clear_string_option(&buf->b_p_keymap); 2303 clear_string_option(&buf->b_p_keymap);