]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1632: memory leak in fuzzy.c v9.1.1632
authorglepnir <glephunter@gmail.com>
Thu, 14 Aug 2025 19:15:44 +0000 (21:15 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 14 Aug 2025 19:15:44 +0000 (21:15 +0200)
Problem:  memory leak in fuzzy.c
Solution: Free fuzmatch, add a few minor refactors
          (glepnir)

fixes neovim CID 584055: fuzmatch leak when count becomes 0
Fix partial allocation failure cleanup in buffer expansion

closes: #17996

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/buffer.c
src/fuzzy.c
src/version.c

index 1ca561fce23da805ac639bd1f2cf7a882989b96b..5937a9e12d1673dd0d28cf6a436810301ebaf1ea 100644 (file)
@@ -2971,7 +2971,11 @@ ExpandBufnames(
            else
                p = vim_strsave(p);
            if (p == NULL)
+           {
+               if (fuzzy && round == 2)
+                   fuzmatch_str_free(fuzmatch, count);
                return FAIL;
+           }
 
            if (!fuzzy)
            {
index c1b216ce590d0952628b991793339b8d0110501b..47407644ebf673b16a308cd44160c0f1ec4ac7dd 100644 (file)
@@ -868,11 +868,10 @@ search_for_fuzzy_match(
     void
 fuzmatch_str_free(fuzmatch_str_T *fuzmatch, int count)
 {
-    int i;
-
     if (fuzmatch == NULL)
        return;
-    for (i = 0; i < count; ++i)
+
+    for (int i = 0; i < count; ++i)
        vim_free(fuzmatch[i].str);
     vim_free(fuzmatch);
 }
@@ -892,7 +891,7 @@ fuzzymatches_to_strmatches(
     int                i;
 
     if (count <= 0)
-       return OK;
+       goto theend;
 
     *matches = ALLOC_MULT(char_u *, count);
     if (*matches == NULL)
@@ -909,8 +908,9 @@ fuzzymatches_to_strmatches(
 
     for (i = 0; i < count; i++)
        (*matches)[i] = fuzmatch[i].str;
-    vim_free(fuzmatch);
 
+theend:
+    vim_free(fuzmatch);
     return OK;
 }
 
index 2f6fbeb82be84281c145c28f3a6cdea99c0dd52a..4f6c70843183490e1cac022d640f016360792964 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1632,
 /**/
     1631,
 /**/