# HG changeset patch # User Bram Moolenaar # Date 1649610903 -7200 # Node ID 813660733869ef83cb104c93a55acf399c0c67dc # Parent e1b7812a4f3b2cb8d99f1a4884fe54c97e4574ad patch 8.2.4732: duplicate code to free fuzzy matches Commit: https://github.com/vim/vim/commit/c6e0a5e98c07d898e829d62bd938b1cc1fd37e94 Author: Bram Moolenaar Date: Sun Apr 10 18:09:06 2022 +0100 patch 8.2.4732: duplicate code to free fuzzy matches Problem: Duplicate code to free fuzzy matches. Solution: Bring back fuzmatch_str_free(). diff --git a/src/cmdexpand.c b/src/cmdexpand.c --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -2877,13 +2877,7 @@ ExpandGeneric( ga_clear_strings(&ga); return FAIL; } - - for (i = 0; i < ga.ga_len; ++i) - { - fuzmatch = &((fuzmatch_str_T *)ga.ga_data)[i]; - vim_free(fuzmatch->str); - } - ga_clear(&ga); + fuzmatch_str_free(ga.ga_data, ga.ga_len); return FAIL; } diff --git a/src/proto/search.pro b/src/proto/search.pro --- a/src/proto/search.pro +++ b/src/proto/search.pro @@ -41,5 +41,6 @@ int fuzzy_match(char_u *str, char_u *pat void f_matchfuzzy(typval_T *argvars, typval_T *rettv); void f_matchfuzzypos(typval_T *argvars, typval_T *rettv); int fuzzy_match_str(char_u *str, char_u *pat); -int fuzzymatches_to_strmatches(fuzmatch_str_T *fuzmatch, char_u ***matches, int count, int funcsort); +void fuzmatch_str_free(fuzmatch_str_T *fuzmatch, int count); +int fuzzymatches_to_strmatches(fuzmatch_str_T *fuzmatch, char_u ***matches, int count, int funcsort); /* vim: set ft=c : */ diff --git a/src/search.c b/src/search.c --- 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; } diff --git a/src/version.c b/src/version.c --- 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 */ /**/ + 4732, +/**/ 4731, /**/ 4730,