diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-14 21:00:08 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 17:40:31 +0800 |
commit | 3c16e75ae194f728c703032084a8f6dd0833a563 (patch) | |
tree | 6c6807eabb1206e23feb9557c0fa2492a3672ccd | |
parent | 3ad8c08acc506555667a070cf83c410ac9334f1e (diff) | |
download | rneovim-3c16e75ae194f728c703032084a8f6dd0833a563.tar.gz rneovim-3c16e75ae194f728c703032084a8f6dd0833a563.tar.bz2 rneovim-3c16e75ae194f728c703032084a8f6dd0833a563.zip |
vim-patch:8.2.4783: Coverity warns for leaking memory
Problem: Coverity warns for leaking memory.
Solution: Use another strategy freeing "theline".
https://github.com/vim/vim/commit/42ccb8d74700506936567b0eb6d11def5e25e1dd
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/eval/vars.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 3905cf82a6..048b5ee2aa 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -178,12 +178,14 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) return NULL; } + char *theline = NULL; list_T *l = tv_list_alloc(0); for (;;) { int mi = 0; int ti = 0; - char *theline = eap->getline(NUL, eap->cookie, 0, false); + xfree(theline); + theline = eap->getline(NUL, eap->cookie, 0, false); if (theline == NULL) { semsg(_("E990: Missing end marker '%s'"), marker); break; @@ -196,14 +198,12 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) mi = marker_indent_len; } if (strcmp(marker, theline + mi) == 0) { - xfree(theline); break; } // If expression evaluation failed in the heredoc, then skip till the // end marker. if (eval_failed) { - xfree(theline); continue; } @@ -231,7 +231,6 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) str = eval_all_expr_in_str(str); if (str == NULL) { // expression evaluation failed - xfree(theline); eval_failed = true; continue; } @@ -240,8 +239,8 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd) } tv_list_append_string(l, str, -1); - xfree(theline); } + xfree(theline); xfree(text_indent); if (eval_failed) { |