From b5ec9eec2d7f2d84d0b0a3c044d7f6b6fd3ec9b1 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Sat, 1 Feb 2025 21:10:40 +0000 Subject: [PATCH] GH-91048: Correct error path in testexternalinspection --- Modules/_testexternalinspection.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Modules/_testexternalinspection.c b/Modules/_testexternalinspection.c index 22074c81b7405f..efd3b8da92ae8d 100644 --- a/Modules/_testexternalinspection.c +++ b/Modules/_testexternalinspection.c @@ -410,6 +410,7 @@ get_py_runtime(pid_t pid) { uintptr_t address = search_map_for_section(pid, "PyRuntime", "libpython"); if (address == 0) { + PyErr_Clear(); address = search_map_for_section(pid, "PyRuntime", "python"); } return address; @@ -1457,6 +1458,13 @@ get_stack_trace(PyObject* self, PyObject* args) } uintptr_t runtime_start_address = get_py_runtime(pid); + if (runtime_start_address == 0) { + if (!PyErr_Occurred()) { + PyErr_SetString( + PyExc_RuntimeError, "Failed to get .PyRuntime address"); + } + return NULL; + } struct _Py_DebugOffsets local_debug_offsets; if (read_offsets(pid, &runtime_start_address, &local_debug_offsets)) { @@ -1510,6 +1518,13 @@ get_async_stack_trace(PyObject* self, PyObject* args) } uintptr_t runtime_start_address = get_py_runtime(pid); + if (runtime_start_address == 0) { + if (!PyErr_Occurred()) { + PyErr_SetString( + PyExc_RuntimeError, "Failed to get .PyRuntime address"); + } + return NULL; + } struct _Py_DebugOffsets local_debug_offsets; if (read_offsets(pid, &runtime_start_address, &local_debug_offsets)) {