vim-patch:8.2.4783: Coverity warns for leaking memory

Problem:    Coverity warns for leaking memory.
Solution:   Use another strategy freeing "theline".

42ccb8d747

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2023-04-14 21:00:08 +08:00
parent 3ad8c08acc
commit 3c16e75ae1

View File

@@ -178,12 +178,14 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
return NULL; return NULL;
} }
char *theline = NULL;
list_T *l = tv_list_alloc(0); list_T *l = tv_list_alloc(0);
for (;;) { for (;;) {
int mi = 0; int mi = 0;
int ti = 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) { if (theline == NULL) {
semsg(_("E990: Missing end marker '%s'"), marker); semsg(_("E990: Missing end marker '%s'"), marker);
break; break;
@@ -196,14 +198,12 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
mi = marker_indent_len; mi = marker_indent_len;
} }
if (strcmp(marker, theline + mi) == 0) { if (strcmp(marker, theline + mi) == 0) {
xfree(theline);
break; break;
} }
// If expression evaluation failed in the heredoc, then skip till the // If expression evaluation failed in the heredoc, then skip till the
// end marker. // end marker.
if (eval_failed) { if (eval_failed) {
xfree(theline);
continue; continue;
} }
@@ -231,7 +231,6 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
str = eval_all_expr_in_str(str); str = eval_all_expr_in_str(str);
if (str == NULL) { if (str == NULL) {
// expression evaluation failed // expression evaluation failed
xfree(theline);
eval_failed = true; eval_failed = true;
continue; continue;
} }
@@ -240,8 +239,8 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
} }
tv_list_append_string(l, str, -1); tv_list_append_string(l, str, -1);
xfree(theline);
} }
xfree(theline);
xfree(text_indent); xfree(text_indent);
if (eval_failed) { if (eval_failed) {