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

updated for version 7.3.898

Problem:    Memory leak reported by valgrind in test 91.
Solution:   Only use default argument when needed.
This commit is contained in:
Bram Moolenaar
2013-04-15 15:15:35 +02:00
parent 768baacdc8
commit 54c34fa6f5
4 changed files with 47 additions and 30 deletions

View File

@@ -11120,20 +11120,15 @@ f_getbufvar(argvars, rettv)
buf_T *save_curbuf;
char_u *varname;
dictitem_T *v;
int done = FALSE;
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
varname = get_tv_string_chk(&argvars[1]);
++emsg_off;
buf = get_buf_tv(&argvars[0], FALSE);
if (argvars[2].v_type != VAR_UNKNOWN)
/* set the default value */
copy_tv(&argvars[2], rettv);
else
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
}
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (buf != NULL && varname != NULL)
{
@@ -11142,11 +11137,15 @@ f_getbufvar(argvars, rettv)
curbuf = buf;
if (*varname == '&') /* buffer-local-option */
get_option_tv(&varname, rettv, TRUE);
{
if (get_option_tv(&varname, rettv, TRUE) == OK)
done = TRUE;
}
else if (STRCMP(varname, "changedtick") == 0)
{
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = curbuf->b_changedtick;
done = TRUE;
}
else
{
@@ -11155,13 +11154,20 @@ f_getbufvar(argvars, rettv)
v = find_var_in_ht(&curbuf->b_vars->dv_hashtab,
'b', varname, FALSE);
if (v != NULL)
{
copy_tv(&v->di_tv, rettv);
done = TRUE;
}
}
/* restore previous notion of curbuf */
curbuf = save_curbuf;
}
if (!done && argvars[2].v_type != VAR_UNKNOWN)
/* use the default value */
copy_tv(&argvars[2], rettv);
--emsg_off;
}
@@ -11767,6 +11773,7 @@ f_gettabvar(argvars, rettv)
tabpage_T *tp;
dictitem_T *v;
char_u *varname;
int done = FALSE;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
@@ -11778,11 +11785,13 @@ f_gettabvar(argvars, rettv)
/* look up the variable */
v = find_var_in_ht(&tp->tp_vars->dv_hashtab, 0, varname, FALSE);
if (v != NULL)
{
copy_tv(&v->di_tv, rettv);
else if (argvars[2].v_type != VAR_UNKNOWN)
copy_tv(&argvars[2], rettv);
done = TRUE;
}
}
else if (argvars[2].v_type != VAR_UNKNOWN)
if (!done && argvars[2].v_type != VAR_UNKNOWN)
copy_tv(&argvars[2], rettv);
}
@@ -11894,6 +11903,7 @@ getwinvar(argvars, rettv, off)
char_u *varname;
dictitem_T *v;
tabpage_T *tp;
int done = FALSE;
#ifdef FEAT_WINDOWS
if (off == 1)
@@ -11905,14 +11915,8 @@ getwinvar(argvars, rettv, off)
varname = get_tv_string_chk(&argvars[off + 1]);
++emsg_off;
if (argvars[off + 2].v_type != VAR_UNKNOWN)
/* set the default return value */
copy_tv(&argvars[off + 2], rettv);
else
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
}
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (win != NULL && varname != NULL)
{
@@ -11923,14 +11927,20 @@ getwinvar(argvars, rettv, off)
curbuf = win->w_buffer;
if (*varname == '&') /* window-local-option */
get_option_tv(&varname, rettv, 1);
{
if (get_option_tv(&varname, rettv, 1) == OK)
done = TRUE;
}
else
{
/* Look up the variable. */
/* Let getwinvar({nr}, "") return the "w:" dictionary. */
v = find_var_in_ht(&win->w_vars->dv_hashtab, 'w', varname, FALSE);
if (v != NULL)
{
copy_tv(&v->di_tv, rettv);
done = TRUE;
}
}
/* restore previous notion of curwin */
@@ -11938,6 +11948,10 @@ getwinvar(argvars, rettv, off)
curbuf = curwin->w_buffer;
}
if (!done && argvars[off + 2].v_type != VAR_UNKNOWN)
/* use the default return value */
copy_tv(&argvars[off + 2], rettv);
--emsg_off;
}

View File

@@ -4,9 +4,10 @@ vim: set ft=vim :
STARTTEST
:so small.vim
:"
:" test for getbufvar()
:let b:var_num = 1234
:let def_num = 5678
:" Test for getbufvar()
:" Use strings to test for memory leaks.
:let b:var_num = '1234'
:let def_num = '5678'
:$put =string(getbufvar(1, 'var_num'))
:$put =string(getbufvar(1, 'var_num', def_num))
:$put =string(getbufvar(1, ''))

View File

@@ -1,13 +1,13 @@
start:
1234
1234
{'var_num': 1234}
{'var_num': 1234}
5678
'1234'
'1234'
{'var_num': '1234'}
{'var_num': '1234'}
'5678'
{}
{}
''
5678
'5678'
0
0
'Dance'

View File

@@ -728,6 +728,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
898,
/**/
897,
/**/