changeset 28518:1a2643893aa4 v8.2.4783

patch 8.2.4783: Coverity warns for leaking memory Commit: https://github.com/vim/vim/commit/42ccb8d74700506936567b0eb6d11def5e25e1dd Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 18 15:45:23 2022 +0100 patch 8.2.4783: Coverity warns for leaking memory Problem: Coverity warns for leaking memory. Solution: Use another strategy freeing "theline".
author Bram Moolenaar <Bram@vim.org>
date Mon, 18 Apr 2022 17:00:03 +0200
parents f73a9bdff3a3
children d217f46c3815
files src/evalvars.c src/version.c
diffstat 2 files changed, 5 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -684,7 +684,7 @@ eval_all_expr_in_str(char_u *str)
     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 @@ heredoc_get(exarg_T *eap, char_u *cmd, i
 	int	mi = 0;
 	int	ti = 0;
 
+	vim_free(theline);
 	theline = eap->getline(NUL, eap->cookie, 0, FALSE);
 	if (theline == NULL)
 	{
@@ -789,18 +790,12 @@ heredoc_get(exarg_T *eap, char_u *cmd, i
 		&& 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 @@ heredoc_get(exarg_T *eap, char_u *cmd, i
 	    if (str == NULL)
 	    {
 		// expression evaluation failed
-		vim_free(theline);
 		eval_failed = TRUE;
 		continue;
 	    }
@@ -837,8 +831,8 @@ heredoc_get(exarg_T *eap, char_u *cmd, i
 
 	if (list_append_string(l, str, -1) == FAIL)
 	    break;
-	vim_free(theline);
     }
+    vim_free(theline);
     vim_free(text_indent);
 
     if (eval_failed)
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4783,
+/**/
     4782,
 /**/
     4781,