From 7afcfb6c9ac53cb4192974934d6cdc360f4bebc7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 15 Aug 2025 06:51:38 +0800 Subject: [PATCH] vim-patch:9.1.1632: memory leak in fuzzy.c 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: vim/vim#17996 https://github.com/vim/vim/commit/03d6e06edd0aaf2f591d74349cb25dbeca5895ef Co-authored-by: glepnir --- src/nvim/fuzzy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/fuzzy.c b/src/nvim/fuzzy.c index 173fcc87a5..396c4b7e5a 100644 --- a/src/nvim/fuzzy.c +++ b/src/nvim/fuzzy.c @@ -690,7 +690,7 @@ void fuzzymatches_to_strmatches(fuzmatch_str_T *const fuzmatch, char ***const ma FUNC_ATTR_NONNULL_ARG(2) { if (count <= 0) { - return; + goto theend; } *matches = xmalloc((size_t)count * sizeof(char *)); @@ -705,6 +705,8 @@ void fuzzymatches_to_strmatches(fuzmatch_str_T *const fuzmatch, char ***const ma for (int i = 0; i < count; i++) { (*matches)[i] = fuzmatch[i].str; } + +theend: xfree(fuzmatch); }