patch 8.2.4783: Coverity warns for leaking memory
Problem: Coverity warns for leaking memory.
Solution: Use another strategy freeing "theline".
diff --git a/src/evalvars.c b/src/evalvars.c
index 5f04406..c83aa61 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -684,7 +684,7 @@
list_T *
heredoc_get(exarg_T *eap, char_u *cmd, int script_get)
{
- char_u *theline;
+ char_u *theline = NULL;
char_u *marker;
list_T *l;
char_u *p;
@@ -776,6 +776,7 @@
int mi = 0;
int ti = 0;
+ vim_free(theline);
theline = eap->getline(NUL, eap->cookie, 0, FALSE);
if (theline == NULL)
{
@@ -789,18 +790,12 @@
&& STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0)
mi = marker_indent_len;
if (STRCMP(marker, theline + mi) == 0)
- {
- vim_free(theline);
break;
- }
// If expression evaluation failed in the heredoc, then skip till the
// end marker.
if (eval_failed)
- {
- vim_free(theline);
continue;
- }
if (text_indent_len == -1 && *theline != NUL)
{
@@ -827,7 +822,6 @@
if (str == NULL)
{
// expression evaluation failed
- vim_free(theline);
eval_failed = TRUE;
continue;
}
@@ -837,8 +831,8 @@
if (list_append_string(l, str, -1) == FAIL)
break;
- vim_free(theline);
}
+ vim_free(theline);
vim_free(text_indent);
if (eval_failed)