aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c6
-rw-r--r--src/nvim/window.c37
2 files changed, 36 insertions, 7 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 0b72dd1885..f1f32076bf 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -840,11 +840,7 @@ static void clear_wininfo(buf_T *buf)
while (buf->b_wininfo != NULL) {
wip = buf->b_wininfo;
buf->b_wininfo = wip->wi_next;
- if (wip->wi_optset) {
- clear_winopt(&wip->wi_opt);
- deleteFoldRecurse(buf, &wip->wi_folds);
- }
- xfree(wip);
+ free_wininfo(wip, buf);
}
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index aea60fe24c..d051e8e467 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -4597,6 +4597,18 @@ static win_T *win_alloc(win_T *after, int hidden)
}
+// Free one wininfo_T.
+void
+free_wininfo(wininfo_T *wip, buf_T *bp)
+{
+ if (wip->wi_optset) {
+ clear_winopt(&wip->wi_opt);
+ deleteFoldRecurse(bp, &wip->wi_folds);
+ }
+ xfree(wip);
+}
+
+
/*
* Remove window 'wp' from the window list and free the structure.
*/
@@ -4647,9 +4659,30 @@ win_free (
/* Remove the window from the b_wininfo lists, it may happen that the
* freed memory is re-used for another window. */
FOR_ALL_BUFFERS(buf) {
- for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
- if (wip->wi_win == wp)
+ for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) {
+ if (wip->wi_win == wp) {
+ wininfo_T *wip2;
+
+ // If there already is an entry with "wi_win" set to NULL it
+ // must be removed, it would never be used.
+ for (wip2 = buf->b_wininfo; wip2 != NULL; wip2 = wip2->wi_next) {
+ if (wip2->wi_win == NULL) {
+ if (wip2->wi_next != NULL) {
+ wip2->wi_next->wi_prev = wip2->wi_prev;
+ }
+ if (wip2->wi_prev == NULL) {
+ buf->b_wininfo = wip2->wi_next;
+ } else {
+ wip2->wi_prev->wi_next = wip2->wi_next;
+ }
+ free_wininfo(wip2, buf);
+ break;
+ }
+ }
+
wip->wi_win = NULL;
+ }
+ }
}
clear_matches(wp);