]> granicus.if.org Git - vim/commitdiff
patch 8.0.0698: crash on exit when using Python function in timer. v8.0.0698
authorBram Moolenaar <Bram@vim.org>
Fri, 7 Jul 2017 12:50:44 +0000 (14:50 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 7 Jul 2017 12:50:44 +0000 (14:50 +0200)
Problem:    When a timer uses ":pyeval" or another Python command and it
            happens to be triggered while exiting a Crash may happen.
            (Ricky Zhou)
Solution:   Avoid running a Python command after python_end() was called.
            Do not trigger timers while exiting.  (closes #1824)

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

index 74dae92b5b0746be5f8e272f53967a4520821b94..3efa8ca2e5be1afa3f6509f5bfd79dd27b64ffce 100644 (file)
@@ -1183,6 +1183,7 @@ timer_callback(timer_T *timer)
 /*
  * Call timers that are due.
  * Return the time in msec until the next timer is due.
+ * Returns -1 if there are no pending timers.
  */
     long
 check_due_timer(void)
@@ -1197,6 +1198,10 @@ check_due_timer(void)
 # ifdef WIN3264
     LARGE_INTEGER   fr;
 
+    /* Don't run any timers while exiting. */
+    if (exiting)
+       return next_due;
+
     QueryPerformanceFrequency(&fr);
 # endif
     profile_start(&now);
index 6b2ce56ef249831525dd10e10d6abd0041cc8b48..a280459db0e86754eb06b92b900f7b395b6b3241 100644 (file)
@@ -779,6 +779,7 @@ get_exceptions(void)
 
 static int initialised = 0;
 #define PYINITIALISED initialised
+static int python_end_called = FALSE;
 
 #define DESTRUCTOR_FINISH(self) self->ob_type->tp_free((PyObject*)self);
 
@@ -878,6 +879,7 @@ python_end(void)
     if (recurse != 0)
        return;
 
+    python_end_called = TRUE;
     ++recurse;
 
 #ifdef DYNAMIC_PYTHON
@@ -1040,6 +1042,8 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
     }
     ++recursive;
 #endif
+    if (python_end_called)
+       return;
 
 #if defined(MACOS) && !defined(MACOS_X_UNIX)
     GetPort(&oldPort);
@@ -1568,7 +1572,7 @@ do_pyeval (char_u *str, typval_T *rettv)
            (rangeinitializer) init_range_eval,
            (runner) run_eval,
            (void *) rettv);
-    switch(rettv->v_type)
+    switch (rettv->v_type)
     {
        case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
        case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
index d68ab85a864218dbd6500199438e5d03da5e99f2..6949b02ef53af160c5bf5cf2efbf625f63ca55a1 100644 (file)
@@ -733,8 +733,8 @@ get_py3_exceptions(void)
 #endif /* DYNAMIC_PYTHON3 */
 
 static int py3initialised = 0;
-
 #define PYINITIALISED py3initialised
+static int python_end_called = FALSE;
 
 #define DESTRUCTOR_FINISH(self) Py_TYPE(self)->tp_free((PyObject*)self)
 
@@ -817,6 +817,7 @@ python3_end(void)
     if (recurse != 0)
        return;
 
+    python_end_called = TRUE;
     ++recurse;
 
 #ifdef DYNAMIC_PYTHON3
@@ -938,6 +939,9 @@ DoPyCommand(const char *cmd, rangeinitializer init_range, runner run, void *arg)
     PyObject           *cmdbytes;
     PyGILState_STATE   pygilstate;
 
+    if (python_end_called)
+       goto theend;
+
 #if defined(MACOS) && !defined(MACOS_X_UNIX)
     GetPort(&oldPort);
     /* Check if the Python library is available */
index bd09de5d941ffc15e6a4f07e2f3b352c2f9f65ea..bd4c3e13a9b27a852040d1138eabd8f5b8f613d5 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    698,
 /**/
     697,
 /**/