0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.1.1021: pyeval() and py3eval() leak memory

Problem:    pyeval() and py3eval() leak memory.
Solution:   Do not increase the reference count twice. (Ozaki Kiichi,
            closes #4129)
This commit is contained in:
Bram Moolenaar
2019-03-19 22:22:55 +01:00
parent 828bff1f9b
commit 8e9a24a127
3 changed files with 12 additions and 38 deletions

View File

@@ -1555,30 +1555,16 @@ FunctionGetattr(PyObject *self, char *name)
} }
void void
do_pyeval (char_u *str, typval_T *rettv) do_pyeval(char_u *str, typval_T *rettv)
{ {
DoPyCommand((char *) str, DoPyCommand((char *) str,
(rangeinitializer) init_range_eval, (rangeinitializer) init_range_eval,
(runner) run_eval, (runner) run_eval,
(void *) rettv); (void *) rettv);
switch (rettv->v_type) if (rettv->v_type == VAR_UNKNOWN)
{ {
case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break; rettv->v_type = VAR_NUMBER;
case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break; rettv->vval.v_number = 0;
case VAR_FUNC: func_ref(rettv->vval.v_string); break;
case VAR_PARTIAL: ++rettv->vval.v_partial->pt_refcount; break;
case VAR_UNKNOWN:
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
break;
case VAR_NUMBER:
case VAR_STRING:
case VAR_FLOAT:
case VAR_SPECIAL:
case VAR_JOB:
case VAR_CHANNEL:
case VAR_BLOB:
break;
} }
} }
@@ -1594,7 +1580,7 @@ Py_GetProgramName(void)
#endif /* Python 1.4 */ #endif /* Python 1.4 */
int int
set_ref_in_python (int copyID) set_ref_in_python(int copyID)
{ {
return set_ref_in_py(copyID); return set_ref_in_py(copyID);
} }

View File

@@ -1663,35 +1663,21 @@ LineToString(const char *str)
} }
void void
do_py3eval (char_u *str, typval_T *rettv) do_py3eval(char_u *str, typval_T *rettv)
{ {
DoPyCommand((char *) str, DoPyCommand((char *) str,
(rangeinitializer) init_range_eval, (rangeinitializer) init_range_eval,
(runner) run_eval, (runner) run_eval,
(void *) rettv); (void *) rettv);
switch(rettv->v_type) if (rettv->v_type == VAR_UNKNOWN)
{ {
case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break; rettv->v_type = VAR_NUMBER;
case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break; rettv->vval.v_number = 0;
case VAR_FUNC: func_ref(rettv->vval.v_string); break;
case VAR_PARTIAL: ++rettv->vval.v_partial->pt_refcount; break;
case VAR_UNKNOWN:
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0;
break;
case VAR_NUMBER:
case VAR_STRING:
case VAR_FLOAT:
case VAR_SPECIAL:
case VAR_JOB:
case VAR_CHANNEL:
case VAR_BLOB:
break;
} }
} }
int int
set_ref_in_python3 (int copyID) set_ref_in_python3(int copyID)
{ {
return set_ref_in_py(copyID); return set_ref_in_py(copyID);
} }

View File

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