aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-12-16 13:31:59 +0100
committerbfredl <bjorn.linse@gmail.com>2025-01-14 14:47:35 +0100
commit59da82abd91e3be7eb5403c14de012cd149a1c84 (patch)
treef730d1b92baaf3915f8d20e8235bfd2c723ba6e1 /src
parent2d6f57b2891247f9ca0f6fb75c4b93fb2c714dc4 (diff)
downloadrneovim-59da82abd91e3be7eb5403c14de012cd149a1c84.tar.gz
rneovim-59da82abd91e3be7eb5403c14de012cd149a1c84.tar.bz2
rneovim-59da82abd91e3be7eb5403c14de012cd149a1c84.zip
fix(wininfo): when freeing windows, free the lowest priority wininfo
On master (and also before #31539) closing a window could cause the used wininfo for a buffer to change. This is due to always removing the previous NULL wininfo when deleting a window, even if that wininfo had higher priority than the the deleted window's own wininfo. Instead delete the wininfo with lowest priority. This retains the memory saving efect while not affecting the effective value of window options and so on.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/window.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index b1c483547c..190ac500b0 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -5242,11 +5242,13 @@ void win_free(win_T *wp, tabpage_T *tp)
// freed memory is re-used for another window.
FOR_ALL_BUFFERS(buf) {
WinInfo *wip_wp = NULL;
+ size_t pos_wip = kv_size(buf->b_wininfo);
size_t pos_null = kv_size(buf->b_wininfo);
for (size_t i = 0; i < kv_size(buf->b_wininfo); i++) {
WinInfo *wip = kv_A(buf->b_wininfo, i);
if (wip->wi_win == wp) {
wip_wp = wip;
+ pos_wip = i;
} else if (wip->wi_win == NULL) {
pos_null = i;
}
@@ -5254,11 +5256,12 @@ void win_free(win_T *wp, tabpage_T *tp)
if (wip_wp) {
wip_wp->wi_win = NULL;
- // If there already is an entry with "wi_win" set to NULL it
- // must be removed, it would never be used.
+ // If there already is an entry with "wi_win" set to NULL, only
+ // the first entry with NULL will ever be used, delete the other one.
if (pos_null < kv_size(buf->b_wininfo)) {
- free_wininfo(kv_A(buf->b_wininfo, pos_null), buf);
- kv_shift(buf->b_wininfo, pos_null, 1);
+ size_t pos_delete = MAX(pos_null, pos_wip);
+ free_wininfo(kv_A(buf->b_wininfo, pos_delete), buf);
+ kv_shift(buf->b_wininfo, pos_delete, 1);
}
}
}