0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.0573: using :version twice leaks memory

Problem:    using :version twice leaks memory
Solution:   Only initialize variables once. (Dominique Pelle, closes #5917)
This commit is contained in:
Bram Moolenaar 2020-04-13 18:25:33 +02:00
parent df1956075d
commit 278e83863b
5 changed files with 30 additions and 13 deletions

View File

@ -1258,7 +1258,7 @@ extern char *Version;
#if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC)
extern char longVersion[];
#else
EXTERN char *longVersion;
EXTERN char *longVersion INIT(= NULL);
#endif
/*

View File

@ -285,6 +285,7 @@ NEW_TESTS = \
test_utf8 \
test_utf8_comparisons \
test_vartabs \
test_version \
$(TEST_VIM9) \
test_viminfo \
test_vimscript \

View File

@ -32,4 +32,5 @@ source test_tabline.vim
source test_tagcase.vim
source test_tagfunc.vim
source test_unlet.vim
source test_version.vim
source test_wnext.vim

View File

@ -0,0 +1,10 @@
" Test :version Ex command
func Test_version()
" version should always return the same string.
let v1 = execute('version')
let v2 = execute('version')
call assert_equal(v1, v2)
call assert_match("^\n\nVIM - Vi IMproved .*", v1)
endfunc

View File

@ -54,19 +54,22 @@ init_longVersion(void)
void
init_longVersion(void)
{
char *date_time = __DATE__ " " __TIME__;
char *msg = _("%s (%s, compiled %s)");
size_t len = strlen(msg)
+ strlen(VIM_VERSION_LONG_ONLY)
+ strlen(VIM_VERSION_DATE_ONLY)
+ strlen(date_time);
longVersion = alloc(len);
if (longVersion == NULL)
longVersion = VIM_VERSION_LONG;
else
vim_snprintf(longVersion, len, msg,
VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
{
char *date_time = __DATE__ " " __TIME__;
char *msg = _("%s (%s, compiled %s)");
size_t len = strlen(msg)
+ strlen(VIM_VERSION_LONG_ONLY)
+ strlen(VIM_VERSION_DATE_ONLY)
+ strlen(date_time);
longVersion = alloc(len);
if (longVersion == NULL)
longVersion = VIM_VERSION_LONG;
else
vim_snprintf(longVersion, len, msg,
VIM_VERSION_LONG_ONLY, VIM_VERSION_DATE_ONLY, date_time);
}
}
# endif
#else
@ -738,6 +741,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
573,
/**/
572,
/**/