]> granicus.if.org Git - vim/commitdiff
patch 8.1.1021: pyeval() and py3eval() leak memory v8.1.1021
authorBram Moolenaar <Bram@vim.org>
Tue, 19 Mar 2019 21:22:55 +0000 (22:22 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 19 Mar 2019 21:22:55 +0000 (22:22 +0100)
Problem:    pyeval() and py3eval() leak memory.
Solution:   Do not increase the reference count twice. (Ozaki Kiichi,
            closes #4129)

src/if_python.c
src/if_python3.c
src/version.c

index c0a3fe1055c788b00ea0724ea35e72d578a4a36c..9f9c257eed920e07f35f01e50f89001b87049b05 100644 (file)
@@ -1555,30 +1555,16 @@ FunctionGetattr(PyObject *self, char *name)
 }
 
     void
-do_pyeval (char_u *str, typval_T *rettv)
+do_pyeval(char_u *str, typval_T *rettv)
 {
     DoPyCommand((char *) str,
            (rangeinitializer) init_range_eval,
            (runner) run_eval,
            (void *) rettv);
-    switch (rettv->v_type)
+    if (rettv->v_type == VAR_UNKNOWN)
     {
-       case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
-       case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
-       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;
+       rettv->v_type = VAR_NUMBER;
+       rettv->vval.v_number = 0;
     }
 }
 
@@ -1594,7 +1580,7 @@ Py_GetProgramName(void)
 #endif /* Python 1.4 */
 
     int
-set_ref_in_python (int copyID)
+set_ref_in_python(int copyID)
 {
     return set_ref_in_py(copyID);
 }
index 8b1b5beb6e63994bfcee855af6d33a2cc42a8e7a..e8ab44f3beb2eeb6b00b6aa021e41d1844279232 100644 (file)
@@ -1663,35 +1663,21 @@ LineToString(const char *str)
 }
 
     void
-do_py3eval (char_u *str, typval_T *rettv)
+do_py3eval(char_u *str, typval_T *rettv)
 {
     DoPyCommand((char *) str,
            (rangeinitializer) init_range_eval,
            (runner) run_eval,
            (void *) rettv);
-    switch(rettv->v_type)
+    if (rettv->v_type == VAR_UNKNOWN)
     {
-       case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
-       case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
-       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;
+       rettv->v_type = VAR_NUMBER;
+       rettv->vval.v_number = 0;
     }
 }
 
     int
-set_ref_in_python3 (int copyID)
+set_ref_in_python3(int copyID)
 {
     return set_ref_in_py(copyID);
 }
index c336046bf4e6992fc76050a75f316ffbe9fa3890..bd02fa5bd9c870c2f16933e36969a5b9130366d6 100644 (file)
@@ -779,6 +779,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1021,
 /**/
     1020,
 /**/