To: vim_dev@googlegroups.com Subject: Patch 9.0.0967 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0967 (after 9.0.0965) Problem: Leaking memory from autocmd windows. Solution: Free window when auc_win is not NULL. Files: src/globals.h, src/autocmd.c, src/window.c, src/quickfix.c, src/eval.c, src/screen.c *** ../vim-9.0.0966/src/globals.h 2022-11-28 18:51:38.951571546 +0000 --- src/globals.h 2022-11-28 19:54:22.455081159 +0000 *************** *** 984,991 **** #define AUCMD_WIN_COUNT 5 typedef struct { ! win_T *auc_win; // window used in aucmd_prepbuf() ! int auc_win_used; // this auc_win is being used } aucmdwin_T; EXTERN aucmdwin_T aucmd_win[AUCMD_WIN_COUNT]; --- 984,992 ---- #define AUCMD_WIN_COUNT 5 typedef struct { ! win_T *auc_win; // Window used in aucmd_prepbuf(). When not NULL the ! // window has been allocated. ! int auc_win_used; // This auc_win is being used. } aucmdwin_T; EXTERN aucmdwin_T aucmd_win[AUCMD_WIN_COUNT]; *** ../vim-9.0.0966/src/autocmd.c 2022-11-28 18:51:38.951571546 +0000 --- src/autocmd.c 2022-11-28 20:16:07.871770314 +0000 *************** *** 653,664 **** } ga_clear(&augroups); ! for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win_used) ! { ! aucmd_win[i].auc_win_used = FALSE; ! win_remove(aucmd_win[i].auc_win, NULL); ! } } #endif --- 653,659 ---- } ga_clear(&augroups); ! // aucmd_win[] is freed in win_free_all() } #endif *************** *** 1553,1564 **** for (auc_idx = 0; auc_idx < AUCMD_WIN_COUNT; ++auc_idx) if (!aucmd_win[auc_idx].auc_win_used) { ! auc_win = win_alloc_popup_win(); if (auc_win != NULL) - { - aucmd_win[auc_idx].auc_win = auc_win; aucmd_win[auc_idx].auc_win_used = TRUE; - } break; } --- 1548,1558 ---- for (auc_idx = 0; auc_idx < AUCMD_WIN_COUNT; ++auc_idx) if (!aucmd_win[auc_idx].auc_win_used) { ! if (aucmd_win[auc_idx].auc_win == NULL) ! aucmd_win[auc_idx].auc_win = win_alloc_popup_win(); ! auc_win = aucmd_win[auc_idx].auc_win; if (auc_win != NULL) aucmd_win[auc_idx].auc_win_used = TRUE; break; } *************** *** 1667,1672 **** --- 1661,1669 ---- // Remove the window and frame from the tree of frames. (void)winframe_remove(curwin, &dummy, NULL); win_remove(curwin, NULL); + + // The window is marked as not used, but it is not freed, it can be + // used again. aucmd_win[aco->use_aucmd_win_idx].auc_win_used = FALSE; last_status(FALSE); // may need to remove last status line *** ../vim-9.0.0966/src/window.c 2022-11-28 18:51:38.959571588 +0000 --- src/window.c 2022-11-28 20:04:28.909170322 +0000 *************** *** 3293,3302 **** tabpage_close(TRUE); for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win_used) { (void)win_free_mem(aucmd_win[i].auc_win, &dummy, NULL); ! aucmd_win[i].auc_win_used = FALSE; } while (firstwin != NULL) --- 3293,3302 ---- tabpage_close(TRUE); for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win != NULL) { (void)win_free_mem(aucmd_win[i].auc_win, &dummy, NULL); ! aucmd_win[i].auc_win = NULL; } while (firstwin != NULL) *** ../vim-9.0.0966/src/quickfix.c 2022-11-28 18:51:38.967571631 +0000 --- src/quickfix.c 2022-11-28 20:09:16.184446664 +0000 *************** *** 6639,6648 **** // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); - } ! if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe)) ! wipe_buffer(newbuf_to_wipe.br_buf, FALSE); // Add back the "dummy" flag, otherwise buflist_findname_stat() won't // skip it. --- 6639,6648 ---- // restore curwin/curbuf and a few other things aucmd_restbuf(&aco); ! if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe)) ! wipe_buffer(newbuf_to_wipe.br_buf, FALSE); ! } // Add back the "dummy" flag, otherwise buflist_findname_stat() won't // skip it. *** ../vim-9.0.0966/src/eval.c 2022-11-28 18:51:38.955571567 +0000 --- src/eval.c 2022-11-28 20:24:13.675231367 +0000 *************** *** 5084,5091 **** FOR_ALL_TAB_WINDOWS(tp, wp) abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, NULL, NULL); for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win_used) abort = abort || set_ref_in_item( &aucmd_win[i].auc_win->w_winvar.di_tv, copyID, NULL, NULL); #ifdef FEAT_PROP_POPUP --- 5084,5092 ---- FOR_ALL_TAB_WINDOWS(tp, wp) abort = abort || set_ref_in_item(&wp->w_winvar.di_tv, copyID, NULL, NULL); + // window-local variables in autocmd windows for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win != NULL) abort = abort || set_ref_in_item( &aucmd_win[i].auc_win->w_winvar.di_tv, copyID, NULL, NULL); #ifdef FEAT_PROP_POPUP *** ../vim-9.0.0966/src/screen.c 2022-11-28 19:10:58.494257355 +0000 --- src/screen.c 2022-11-28 20:25:22.935166296 +0000 *************** *** 2439,2445 **** FOR_ALL_TAB_WINDOWS(tp, wp) win_free_lsize(wp); for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win_used) win_free_lsize(aucmd_win[i].auc_win); #ifdef FEAT_PROP_POPUP // global popup windows --- 2439,2445 ---- FOR_ALL_TAB_WINDOWS(tp, wp) win_free_lsize(wp); for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win != NULL) win_free_lsize(aucmd_win[i].auc_win); #ifdef FEAT_PROP_POPUP // global popup windows *************** *** 2484,2490 **** } } for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win_used && aucmd_win[i].auc_win->w_lines == NULL && win_alloc_lines(aucmd_win[i].auc_win) == FAIL) { --- 2484,2490 ---- } } for (int i = 0; i < AUCMD_WIN_COUNT; ++i) ! if (aucmd_win[i].auc_win != NULL && aucmd_win[i].auc_win->w_lines == NULL && win_alloc_lines(aucmd_win[i].auc_win) == FAIL) { *** ../vim-9.0.0966/src/version.c 2022-11-28 19:10:58.494257355 +0000 --- src/version.c 2022-11-28 20:05:59.996908617 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 967, /**/ -- hundred-and-one symptoms of being an internet addict: 172. You join listservers just for the extra e-mail. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///