Mercurial > vim
comparison src/cmdexpand.c @ 31394:a6b1f1c22374 v9.0.1030
patch 9.0.1030: using freed memory with the cmdline popup menu
Commit: https://github.com/vim/vim/commit/038e6d20e680ce8c850d07f6b035c4e1904c1201
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 8 12:00:50 2022 +0000
patch 9.0.1030: using freed memory with the cmdline popup menu
Problem: Using freed memory with the cmdline popup menu.
Solution: Clear the popup menu when clearing the matches. (closes https://github.com/vim/vim/issues/11677)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 08 Dec 2022 13:15:03 +0100 |
parents | 4f709e5f24d2 |
children | dcd73efec7de |
comparison
equal
deleted
inserted
replaced
31393:d738837013df | 31394:a6b1f1c22374 |
---|---|
367 } | 367 } |
368 | 368 |
369 /* | 369 /* |
370 * Display the cmdline completion matches in a popup menu | 370 * Display the cmdline completion matches in a popup menu |
371 */ | 371 */ |
372 void cmdline_pum_display(void) | 372 void |
373 cmdline_pum_display(void) | |
373 { | 374 { |
374 pum_display(compl_match_array, compl_match_arraysize, compl_selected); | 375 pum_display(compl_match_array, compl_match_arraysize, compl_selected); |
375 } | 376 } |
376 | 377 |
377 /* | 378 /* |
378 * Returns TRUE if the cmdline completion popup menu is being displayed. | 379 * Returns TRUE if the cmdline completion popup menu is being displayed. |
379 */ | 380 */ |
380 int cmdline_pum_active(void) | 381 int |
382 cmdline_pum_active(void) | |
381 { | 383 { |
382 return pum_visible() && compl_match_array != NULL; | 384 return pum_visible() && compl_match_array != NULL; |
383 } | 385 } |
384 | 386 |
385 /* | 387 /* |
386 * Remove the cmdline completion popup menu (if present), free the list of | 388 * Remove the cmdline completion popup menu (if present), free the list of |
387 * items and refresh the screen. | 389 * items and refresh the screen. |
388 */ | 390 */ |
389 void cmdline_pum_remove(void) | 391 void |
392 cmdline_pum_remove(void) | |
390 { | 393 { |
391 int save_p_lz = p_lz; | 394 int save_p_lz = p_lz; |
392 int save_KeyTyped = KeyTyped; | 395 int save_KeyTyped = KeyTyped; |
393 | 396 |
394 pum_undisplay(); | 397 pum_undisplay(); |
401 // When a function is called (e.g. for 'foldtext') KeyTyped might be reset | 404 // When a function is called (e.g. for 'foldtext') KeyTyped might be reset |
402 // as a side effect. | 405 // as a side effect. |
403 KeyTyped = save_KeyTyped; | 406 KeyTyped = save_KeyTyped; |
404 } | 407 } |
405 | 408 |
406 void cmdline_pum_cleanup(cmdline_info_T *cclp) | 409 void |
410 cmdline_pum_cleanup(cmdline_info_T *cclp) | |
407 { | 411 { |
408 cmdline_pum_remove(); | 412 cmdline_pum_remove(); |
409 wildmenu_cleanup(cclp); | 413 wildmenu_cleanup(cclp); |
410 } | 414 } |
411 | 415 |
412 /* | 416 /* |
413 * Returns the starting column number to use for the cmdline completion popup | 417 * Returns the starting column number to use for the cmdline completion popup |
414 * menu. | 418 * menu. |
415 */ | 419 */ |
416 int cmdline_compl_startcol(void) | 420 int |
421 cmdline_compl_startcol(void) | |
417 { | 422 { |
418 return compl_startcol; | 423 return compl_startcol; |
419 } | 424 } |
420 | 425 |
421 /* | 426 /* |
973 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) | 978 if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) |
974 { | 979 { |
975 FreeWild(xp->xp_numfiles, xp->xp_files); | 980 FreeWild(xp->xp_numfiles, xp->xp_files); |
976 xp->xp_numfiles = -1; | 981 xp->xp_numfiles = -1; |
977 VIM_CLEAR(orig_save); | 982 VIM_CLEAR(orig_save); |
983 | |
984 // The entries from xp_files may be used in the PUM, remove it. | |
985 if (compl_match_array != NULL) | |
986 cmdline_pum_remove(); | |
978 } | 987 } |
979 findex = 0; | 988 findex = 0; |
980 | 989 |
981 if (mode == WILD_FREE) // only release file name | 990 if (mode == WILD_FREE) // only release file name |
982 return NULL; | 991 return NULL; |