changeset 28355:f1a3df11d013 v8.2.4703

patch 8.2.4703: memory leak in handling 'cinscopedecls' Commit: https://github.com/vim/vim/commit/cb49a1d934d38cbc0d445af59b71ffe45cbcae75 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 7 13:08:00 2022 +0100 patch 8.2.4703: memory leak in handling 'cinscopedecls' Problem: Memory leak in handling 'cinscopedecls'. Solution: Free the memory before returning.
author Bram Moolenaar <Bram@vim.org>
date Thu, 07 Apr 2022 14:15:03 +0200
parents 24a848f4d593
children 7225ec1e64cc
files src/cindent.c src/version.c
diffstat 2 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/cindent.c
+++ b/src/cindent.c
@@ -425,32 +425,35 @@ cin_islabel_skip(char_u **s)
     static int
 cin_isscopedecl(char_u *p)
 {
-    size_t cinsd_len;
-    char_u *cinsd_buf;
-    char_u *cinsd;
-    size_t len;
-    char_u *skip;
-    char_u *s = cin_skipcomment(p);
+    size_t  cinsd_len;
+    char_u  *cinsd_buf;
+    char_u  *cinsd;
+    size_t  len;
+    char_u  *skip;
+    char_u  *s = cin_skipcomment(p);
+    int	    found = FALSE;
 
     cinsd_len = STRLEN(curbuf->b_p_cinsd) + 1;
     cinsd_buf = alloc(cinsd_len);
-    if (cinsd_buf != NULL)
+    if (cinsd_buf == NULL)
+	return FALSE;
+
+    for (cinsd = curbuf->b_p_cinsd; *cinsd; )
     {
-	for (cinsd = curbuf->b_p_cinsd; *cinsd; )
+	len = copy_option_part(&cinsd, cinsd_buf, cinsd_len, ",");
+	if (STRNCMP(s, cinsd_buf, len) == 0)
 	{
-	    len = copy_option_part(&cinsd, cinsd_buf, cinsd_len, ",");
-	    if (STRNCMP(s, cinsd_buf, len) == 0)
+	    skip = cin_skipcomment(s + len);
+	    if (*skip == ':' && skip[1] != ':')
 	    {
-		skip = cin_skipcomment(s + len);
-		if (*skip == ':' && skip[1] != ':')
-		    return TRUE;
+		found = TRUE;
+		break;
 	    }
 	}
-
-	vim_free(cinsd_buf);
     }
 
-    return FALSE;
+    vim_free(cinsd_buf);
+    return found;
 }
 
 /*
--- 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 */
 /**/
+    4703,
+/**/
     4702,
 /**/
     4701,