From 0cfeedb088ee35f88190f0cb995f7d461d08c959 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 4 Mar 2026 09:05:37 +0800 Subject: [PATCH] vim-patch:9.2.0091: missing out-of-memory checks in quickfix.c Problem: missing out-of-memory checks in quickfix.c Solution: Improve error handline, refactor qf_push_dir() slightly (John Marriott). closes: vim/vim#19528 https://github.com/vim/vim/commit/01554015384e1f8016ee29209e0c370a9e79b80d Co-authored-by: John Marriott --- src/nvim/quickfix.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 779a4ec4d9..198f02a255 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -2365,9 +2365,10 @@ static char *qf_push_dir(char *dirbuf, struct dir_stack_T **stackptr, bool is_fi { struct dir_stack_T *ds_ptr; - // allocate new stack element and hook it in + // allocate new stack element struct dir_stack_T *ds_new = xmalloc(sizeof(struct dir_stack_T)); + // push the new element onto the stack ds_new->next = *stackptr; *stackptr = ds_new; @@ -2383,9 +2384,10 @@ static char *qf_push_dir(char *dirbuf, struct dir_stack_T **stackptr, bool is_fi ds_new = (*stackptr)->next; (*stackptr)->dirname = NULL; while (ds_new) { - xfree((*stackptr)->dirname); - (*stackptr)->dirname = concat_fnames(ds_new->dirname, dirbuf, true); - if (os_isdir((*stackptr)->dirname)) { + char *dirname = concat_fnames(ds_new->dirname, dirbuf, true); + if (os_isdir(dirname)) { + xfree((*stackptr)->dirname); + (*stackptr)->dirname = dirname; break; } @@ -2410,9 +2412,12 @@ static char *qf_push_dir(char *dirbuf, struct dir_stack_T **stackptr, bool is_fi if ((*stackptr)->dirname != NULL) { return (*stackptr)->dirname; } + + // pop the new element from the stack and free it ds_ptr = *stackptr; *stackptr = (*stackptr)->next; xfree(ds_ptr); + return NULL; }