summaryrefslogtreecommitdiffstats
path: root/src/search.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-04-10 18:09:06 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-10 18:09:06 +0100
commitc6e0a5e98c07d898e829d62bd938b1cc1fd37e94 (patch)
tree30d7f2ba11a0532c7cc4fecbf0383d0fd02c058e /src/search.c
parentdb0ea7f2b00c84d84f188c9e9953c4f1887528e7 (diff)
patch 8.2.4732: duplicate code to free fuzzy matchesv8.2.4732
Problem: Duplicate code to free fuzzy matches. Solution: Bring back fuzmatch_str_free().
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/search.c b/src/search.c
index 6a52415e71..470bde2146 100644
--- a/src/search.c
+++ b/src/search.c
@@ -5014,6 +5014,21 @@ fuzzy_match_str(char_u *str, char_u *pat)
}
/*
+ * Free an array of fuzzy string matches "fuzmatch[count]".
+ */
+ void
+fuzmatch_str_free(fuzmatch_str_T *fuzmatch, int count)
+{
+ int i;
+
+ if (fuzmatch == NULL)
+ return;
+ for (i = 0; i < count; ++i)
+ vim_free(fuzmatch[i].str);
+ vim_free(fuzmatch);
+}
+
+/*
* Copy a list of fuzzy matches into a string list after sorting the matches by
* the fuzzy score. Frees the memory allocated for 'fuzmatch'.
* Returns OK on success and FAIL on memory allocation failure.
@@ -5033,9 +5048,7 @@ fuzzymatches_to_strmatches(
*matches = ALLOC_MULT(char_u *, count);
if (*matches == NULL)
{
- for (i = 0; i < count; i++)
- vim_free(fuzmatch[i].str);
- vim_free(fuzmatch);
+ fuzmatch_str_free(fuzmatch, count);
return FAIL;
}