vim-patch:8.1.0843: memory leak when running "make test_cd" #9944

closes #9921
reverts f0a702d116

Problem:    Memory leak when running "make test_cd".
Solution:   Free the stack element when failing. (Dominique Pelle,
            closes vim/vim#3877)
e0de2164f6
This commit is contained in:
Justin M. Keyes
2019-04-28 16:54:00 +02:00
committed by GitHub
parent 33b20ce7de
commit c76c798bf6

View File

@@ -687,20 +687,24 @@ char_u *vim_findfile(void *search_ctx_arg)
if (!vim_isAbsName(stackp->ffs_fix_path) if (!vim_isAbsName(stackp->ffs_fix_path)
&& search_ctx->ffsc_start_dir) { && search_ctx->ffsc_start_dir) {
if (STRLEN(search_ctx->ffsc_start_dir) + 1 >= MAXPATHL) { if (STRLEN(search_ctx->ffsc_start_dir) + 1 >= MAXPATHL) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
STRCPY(file_path, search_ctx->ffsc_start_dir); STRCPY(file_path, search_ctx->ffsc_start_dir);
if (!add_pathsep((char *)file_path)) { if (!add_pathsep((char *)file_path)) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
} }
// append the fix part of the search path // append the fix part of the search path
if (STRLEN(file_path) + STRLEN(stackp->ffs_fix_path) + 1 >= MAXPATHL) { if (STRLEN(file_path) + STRLEN(stackp->ffs_fix_path) + 1 >= MAXPATHL) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
STRCAT(file_path, stackp->ffs_fix_path); STRCAT(file_path, stackp->ffs_fix_path);
if (!add_pathsep((char *)file_path)) { if (!add_pathsep((char *)file_path)) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
@@ -715,6 +719,7 @@ char_u *vim_findfile(void *search_ctx_arg)
if (*p > 0) { if (*p > 0) {
(*p)--; (*p)--;
if (len + 1 >= MAXPATHL) { if (len + 1 >= MAXPATHL) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
file_path[len++] = '*'; file_path[len++] = '*';
@@ -743,6 +748,7 @@ char_u *vim_findfile(void *search_ctx_arg)
while (*rest_of_wildcards while (*rest_of_wildcards
&& !vim_ispathsep(*rest_of_wildcards)) { && !vim_ispathsep(*rest_of_wildcards)) {
if (len + 1 >= MAXPATHL) { if (len + 1 >= MAXPATHL) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
file_path[len++] = *rest_of_wildcards++; file_path[len++] = *rest_of_wildcards++;
@@ -792,10 +798,12 @@ char_u *vim_findfile(void *search_ctx_arg)
// prepare the filename to be checked for existence below // prepare the filename to be checked for existence below
if (STRLEN(stackp->ffs_filearray[i]) + 1 if (STRLEN(stackp->ffs_filearray[i]) + 1
+ STRLEN(search_ctx->ffsc_file_to_search) >= MAXPATHL) { + STRLEN(search_ctx->ffsc_file_to_search) >= MAXPATHL) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
STRCPY(file_path, stackp->ffs_filearray[i]); STRCPY(file_path, stackp->ffs_filearray[i]);
if (!add_pathsep((char *)file_path)) { if (!add_pathsep((char *)file_path)) {
ff_free_stack_element(stackp);
goto fail; goto fail;
} }
STRCAT(file_path, search_ctx->ffsc_file_to_search); STRCAT(file_path, search_ctx->ffsc_file_to_search);
@@ -964,7 +972,6 @@ char_u *vim_findfile(void *search_ctx_arg)
} }
fail: fail:
ff_free_stack_element(stackp);
xfree(file_path); xfree(file_path);
return NULL; return NULL;
} }