Deinit python subinterpreters in reverse order (last to first).

This appears to work around a crash on OpenBSD with Python 3.9.10.
This commit is contained in:
Todd C. Miller
2022-03-06 18:39:12 -07:00
parent c131b27474
commit dfda098ae7

View File

@@ -736,8 +736,9 @@ python_plugin_unlink(void)
if (Py_IsInitialized()) { if (Py_IsInitialized()) {
sudo_debug_printf(SUDO_DEBUG_NOTICE, "Closing: deinit python %zu subinterpreters\n", sudo_debug_printf(SUDO_DEBUG_NOTICE, "Closing: deinit python %zu subinterpreters\n",
py_ctx.interpreter_count); py_ctx.interpreter_count);
for (size_t i = 0; i < py_ctx.interpreter_count; ++i) { while (py_ctx.interpreter_count != 0) {
PyThreadState *py_interpreter = py_ctx.py_subinterpreters[i]; PyThreadState *py_interpreter =
py_ctx.py_subinterpreters[--py_ctx.interpreter_count];
PyThreadState_Swap(py_interpreter); PyThreadState_Swap(py_interpreter);
Py_EndInterpreter(py_interpreter); Py_EndInterpreter(py_interpreter);
} }