bpo-30598: _PySys_EndInit() now duplicates warnoptions (#1998)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 8 Jun 2017 11:27:47 +0000 (13:27 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Jun 2017 11:27:47 +0000 (13:27 +0200)
Fix a reference in subinterpreters, like test_callbacks_leak() of
test_atexit.

warnoptions is a list used to pass options from the command line to
the sys module constructor. Before this change, the list was shared
by multiple interpreter which is not the expected behaviour. Each
interpreter should have their own independent mutable world.

This change duplicates the list in each interpreter. So each
interpreter owns its own list, so each interpreter can clear its own
list.

Python/sysmodule.c

index 741060189c83170e0441da572cdb48c5f073a3bb..424a88f7086b3e3798e85937751e90248bf955e1 100644 (file)
@@ -2136,10 +2136,10 @@ _PySys_EndInit(PyObject *sysdict)
         if (warnoptions == NULL)
             return -1;
     }
-    else {
-        Py_INCREF(warnoptions);
-    }
-    SET_SYS_FROM_STRING_BORROW_INT_RESULT("warnoptions", warnoptions);
+
+    SET_SYS_FROM_STRING_INT_RESULT("warnoptions",
+                                   PyList_GetSlice(warnoptions,
+                                                   0, Py_SIZE(warnoptions)));
 
     SET_SYS_FROM_STRING_BORROW_INT_RESULT("_xoptions", get_xoptions());