From dfda098ae7513735eb9d67d54481ae42739feb8c Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 6 Mar 2022 18:39:12 -0700 Subject: [PATCH] Deinit python subinterpreters in reverse order (last to first). This appears to work around a crash on OpenBSD with Python 3.9.10. --- plugins/python/python_plugin_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/python/python_plugin_common.c b/plugins/python/python_plugin_common.c index 8dae8a36d..c337dd730 100644 --- a/plugins/python/python_plugin_common.c +++ b/plugins/python/python_plugin_common.c @@ -736,8 +736,9 @@ python_plugin_unlink(void) if (Py_IsInitialized()) { sudo_debug_printf(SUDO_DEBUG_NOTICE, "Closing: deinit python %zu subinterpreters\n", py_ctx.interpreter_count); - for (size_t i = 0; i < py_ctx.interpreter_count; ++i) { - PyThreadState *py_interpreter = py_ctx.py_subinterpreters[i]; + while (py_ctx.interpreter_count != 0) { + PyThreadState *py_interpreter = + py_ctx.py_subinterpreters[--py_ctx.interpreter_count]; PyThreadState_Swap(py_interpreter); Py_EndInterpreter(py_interpreter); }