mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
memory: Free buffers after freeing variables
Avoids use-after-free crashes when compiling with -DEXITFREE.
This commit is contained in:
parent
cd8f07cb75
commit
fe30d8ccef
@ -625,18 +625,6 @@ void free_all_mem(void)
|
||||
/* Destroy all windows. Must come before freeing buffers. */
|
||||
win_free_all();
|
||||
|
||||
/* Free all buffers. Reset 'autochdir' to avoid accessing things that
|
||||
* were freed already. */
|
||||
p_acd = false;
|
||||
for (buf = firstbuf; buf != NULL; ) {
|
||||
bufref_T bufref;
|
||||
set_bufref(&bufref, buf);
|
||||
nextbuf = buf->b_next;
|
||||
close_buffer(NULL, buf, DOBUF_WIPE, false);
|
||||
// Didn't work, try next one.
|
||||
buf = bufref_valid(&bufref) ? nextbuf : firstbuf;
|
||||
}
|
||||
|
||||
free_cmdline_buf();
|
||||
|
||||
/* Clear registers. */
|
||||
@ -660,6 +648,20 @@ void free_all_mem(void)
|
||||
|
||||
eval_clear();
|
||||
|
||||
// Free all buffers. Reset 'autochdir' to avoid accessing things that
|
||||
// were freed already.
|
||||
// Must be after eval_clear to avoid it trying to access b:changedtick after
|
||||
// freeing it.
|
||||
p_acd = false;
|
||||
for (buf = firstbuf; buf != NULL; ) {
|
||||
bufref_T bufref;
|
||||
set_bufref(&bufref, buf);
|
||||
nextbuf = buf->b_next;
|
||||
close_buffer(NULL, buf, DOBUF_WIPE, false);
|
||||
// Didn't work, try next one.
|
||||
buf = bufref_valid(&bufref) ? nextbuf : firstbuf;
|
||||
}
|
||||
|
||||
/* screenlines (can't display anything now!) */
|
||||
free_screenlines();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user