From f0a702d1169a77334f1481d19fc08f8d8413083a Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 22 Jul 2018 21:12:25 -0400 Subject: [PATCH] file_search: free stackp if vim_findfile() failed ff_free_stack_element() accepts NULL ptr and returns early. This removes the need to check if stackp is not NULL. --- src/nvim/file_search.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index ebe6dce5b1..6c1a2f6d7b 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -577,7 +577,7 @@ char_u *vim_findfile(void *search_ctx_arg) char_u *file_path; char_u *rest_of_wildcards; char_u *path_end = NULL; - ff_stack_T *stackp; + ff_stack_T *stackp = NULL; size_t len; char_u *p; char_u *suf; @@ -964,6 +964,7 @@ char_u *vim_findfile(void *search_ctx_arg) } fail: + ff_free_stack_element(stackp); xfree(file_path); return NULL; } @@ -1222,6 +1223,10 @@ static ff_stack_T *ff_pop(ff_search_ctx_T *search_ctx) */ static void ff_free_stack_element(ff_stack_T *stack_ptr) { + if (stack_ptr == NULL) { + return; + } + /* free handles possible NULL pointers */ xfree(stack_ptr->ffs_fix_path); xfree(stack_ptr->ffs_wc_path);