diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-18 14:30:08 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-18 14:31:00 +0800 |
commit | 2a94dcf0c592464222c87f5606799ca51a0b9c07 (patch) | |
tree | 82de440c063b1304bbe9ecbbdbb6845bb0690fc9 | |
parent | a1e0f6c07fc575dfac4cd4c0d8c395b8d3f1a4f4 (diff) | |
download | rneovim-2a94dcf0c592464222c87f5606799ca51a0b9c07.tar.gz rneovim-2a94dcf0c592464222c87f5606799ca51a0b9c07.tar.bz2 rneovim-2a94dcf0c592464222c87f5606799ca51a0b9c07.zip |
vim-patch:9.0.0820: memory leak with empty shell command
Problem: Memory leak with empty shell command.
Solution: Free the empty string.
https://github.com/vim/vim/commit/03d6e6f42b0deeb02d52c8a48c14abe431370c1c
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/ex_cmds.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index db9cf94cba..55dbe17ad6 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1012,10 +1012,13 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } while (trailarg != NULL); - // Don't clear "prevcmd" if there is no command to run. + // Only set "prevcmd" if there is a command to run, otherwise keep te one + // we have. if (strlen(newcmd) > 0) { xfree(prevcmd); prevcmd = newcmd; + } else { + free_newcmd = true; } if (bangredo) { // put cmd in redo buffer for ! command @@ -1031,6 +1034,9 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } // Add quotes around the command, for shells that need them. if (*p_shq != NUL) { + if (free_newcmd) { + xfree(newcmd); + } newcmd = xmalloc(strlen(prevcmd) + 2 * strlen(p_shq) + 1); STRCPY(newcmd, p_shq); STRCAT(newcmd, prevcmd); |