Mercurial > vim
comparison src/ex_docmd.c @ 29117:c7a8d4bf4d04 v8.2.5079
patch 8.2.5079: DirChanged autocommand may use freed memory
Commit: https://github.com/vim/vim/commit/d8c9d32c8932e93008bfd4e8828ed42f4e9f8315
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 12 11:49:16 2022 +0100
patch 8.2.5079: DirChanged autocommand may use freed memory
Problem: DirChanged autocommand may use freed memory. (Shane-XB Qian)
Solution: Free the memory later. (closes https://github.com/vim/vim/issues/10555)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Jun 2022 13:00:03 +0200 |
parents | 3de91964bbd6 |
children | ff98d9c228d4 |
comparison
equal
deleted
inserted
replaced
29116:59b1aab30005 | 29117:c7a8d4bf4d04 |
---|---|
7523 { | 7523 { |
7524 char_u *pdir = NULL; | 7524 char_u *pdir = NULL; |
7525 int dir_differs; | 7525 int dir_differs; |
7526 char_u *acmd_fname = NULL; | 7526 char_u *acmd_fname = NULL; |
7527 char_u **pp; | 7527 char_u **pp; |
7528 char_u *tofree; | |
7528 | 7529 |
7529 if (new_dir == NULL || allbuf_locked()) | 7530 if (new_dir == NULL || allbuf_locked()) |
7530 return FALSE; | 7531 return FALSE; |
7531 | 7532 |
7532 if (vim_strchr(p_cpo, CPO_CHDIR) != NULL && curbufIsChanged() && !forceit) | 7533 if (vim_strchr(p_cpo, CPO_CHDIR) != NULL && curbufIsChanged() && !forceit) |
7599 pp = &curwin->w_prevdir; | 7600 pp = &curwin->w_prevdir; |
7600 else if (scope == CDSCOPE_TABPAGE) | 7601 else if (scope == CDSCOPE_TABPAGE) |
7601 pp = &curtab->tp_prevdir; | 7602 pp = &curtab->tp_prevdir; |
7602 else | 7603 else |
7603 pp = &prev_dir; | 7604 pp = &prev_dir; |
7604 vim_free(*pp); | 7605 tofree = *pp; // new_dir may use this |
7605 *pp = pdir; | 7606 *pp = pdir; |
7606 | 7607 |
7607 post_chdir(scope); | 7608 post_chdir(scope); |
7608 | 7609 |
7609 if (dir_differs) | 7610 if (dir_differs) |
7610 apply_autocmds(EVENT_DIRCHANGED, acmd_fname, new_dir, FALSE, curbuf); | 7611 apply_autocmds(EVENT_DIRCHANGED, acmd_fname, new_dir, FALSE, curbuf); |
7612 vim_free(tofree); | |
7611 return TRUE; | 7613 return TRUE; |
7612 } | 7614 } |
7613 | 7615 |
7614 /* | 7616 /* |
7615 * ":cd", ":tcd", ":lcd", ":chdir" ":tchdir" and ":lchdir". | 7617 * ":cd", ":tcd", ":lcd", ":chdir" ":tchdir" and ":lchdir". |