Mercurial > vim
comparison src/userfunc.c @ 31620:2266b5c4f87b v9.0.1142
patch 9.0.1142: crash and/or memory leak when redefining function
Commit: https://github.com/vim/vim/commit/f057171d8b562c72334fd7c15c89ff787358ce3a
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jan 4 13:16:20 2023 +0000
patch 9.0.1142: crash and/or memory leak when redefining function
Problem: Crash and/or memory leak when redefining function after error.
Solution: Clear pointer after making a copy. Clear arrays on failure.
(closes #11774)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 04 Jan 2023 14:30:03 +0100 |
parents | 53c3df37a2b0 |
children | 5c1b7a87466e |
comparison
equal
deleted
inserted
replaced
31619:50a4ca392ab6 | 31620:2266b5c4f87b |
---|---|
523 { | 523 { |
524 char_u *p; | 524 char_u *p; |
525 | 525 |
526 // Move the last argument "...name: type" to uf_va_name and | 526 // Move the last argument "...name: type" to uf_va_name and |
527 // uf_va_type. | 527 // uf_va_type. |
528 fp->uf_va_name = ((char_u **)fp->uf_args.ga_data) | |
529 [fp->uf_args.ga_len - 1]; | |
530 --fp->uf_args.ga_len; | 528 --fp->uf_args.ga_len; |
529 fp->uf_va_name = ((char_u **)fp->uf_args.ga_data)[fp->uf_args.ga_len]; | |
530 ((char_u **)fp->uf_args.ga_data)[fp->uf_args.ga_len] = NULL; | |
531 p = ((char_u **)argtypes->ga_data)[len]; | 531 p = ((char_u **)argtypes->ga_data)[len]; |
532 if (p == NULL) | 532 if (p == NULL) |
533 // TODO: get type from default value | 533 // TODO: get type from default value |
534 fp->uf_va_type = &t_list_any; | 534 fp->uf_va_type = &t_list_any; |
535 else | 535 else |
4785 | 4785 |
4786 // This may get more lines and make the pointers into the first line | 4786 // This may get more lines and make the pointers into the first line |
4787 // invalid. | 4787 // invalid. |
4788 ++p; | 4788 ++p; |
4789 if (get_function_args(&p, ')', &newargs, | 4789 if (get_function_args(&p, ')', &newargs, |
4790 eap->cmdidx == CMD_def ? &argtypes : NULL, FALSE, | 4790 eap->cmdidx == CMD_def ? &argtypes : NULL, FALSE, |
4791 NULL, &varargs, &default_args, eap->skip, | 4791 NULL, &varargs, &default_args, eap->skip, |
4792 eap, in_class, &newlines, lines_to_free) == FAIL) | 4792 eap, in_class, &newlines, lines_to_free) == FAIL) |
4793 goto errret_2; | 4793 goto errret_2; |
4794 whitep = p; | 4794 whitep = p; |
4795 | 4795 |
5207 fp->uf_script_ctx.sc_version = SCRIPT_VERSION_MAX; | 5207 fp->uf_script_ctx.sc_version = SCRIPT_VERSION_MAX; |
5208 | 5208 |
5209 goto ret_free; | 5209 goto ret_free; |
5210 | 5210 |
5211 erret: | 5211 erret: |
5212 if (fp != NULL) | |
5213 { | |
5214 // these were set to "newargs" and "default_args", which are cleared | |
5215 // below | |
5216 ga_init(&fp->uf_args); | |
5217 ga_init(&fp->uf_def_args); | |
5218 } | |
5219 errret_2: | |
5212 ga_clear_strings(&newargs); | 5220 ga_clear_strings(&newargs); |
5213 ga_clear_strings(&default_args); | 5221 ga_clear_strings(&default_args); |
5214 if (fp != NULL) | |
5215 { | |
5216 ga_init(&fp->uf_args); | |
5217 ga_init(&fp->uf_def_args); | |
5218 } | |
5219 errret_2: | |
5220 ga_clear_strings(&newlines); | 5222 ga_clear_strings(&newlines); |
5221 if (fp != NULL) | 5223 if (fp != NULL) |
5224 { | |
5222 VIM_CLEAR(fp->uf_arg_types); | 5225 VIM_CLEAR(fp->uf_arg_types); |
5226 VIM_CLEAR(fp->uf_va_name); | |
5227 clear_type_list(&fp->uf_type_list); | |
5228 } | |
5223 if (free_fp) | 5229 if (free_fp) |
5224 { | 5230 { |
5225 vim_free(fp); | 5231 vim_free(fp); |
5226 fp = NULL; | 5232 fp = NULL; |
5227 } | 5233 } |