https://github.com/python/cpython/commit/03875414cb2993b609044004732b802fe73f39dd
commit: 03875414cb2993b609044004732b802fe73f39dd
branch: main
author: Neil Schemenauer <[email protected]>
committer: nascheme <[email protected]>
date: 2026-10-29T10:16:59-07:00
summary:
gh-159136: Keep eval-frame recorded function names alive (gh-160836)
Hold a strong reference to func_name in both recording hooks before
PyList_Append can detach while acquiring the recording list lock.
files:
M Modules/_testinternalcapi.c
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 16be593763bf66..5b5516046fff40 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1182,8 +1182,9 @@ record_eval(PyThreadState *tstate, struct
_PyInterpreterFrame *f, int exc)
assert(module != NULL);
module_state *state = get_module_state(module);
Py_DECREF(module);
- int res = PyList_Append(state->record_list,
- FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
+ PyObject *name =
Py_NewRef(FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
+ int res = PyList_Append(state->record_list, name);
+ Py_DECREF(name);
if (res < 0) {
return NULL;
}
@@ -1244,8 +1245,9 @@ record_eval_interp(PyThreadState *tstate, struct
_PyInterpreterFrame *f, int exc
assert(module != NULL);
module_state *state = get_module_state(module);
Py_DECREF(module);
- int res = PyList_Append(state->record_list,
- FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
+ PyObject *name =
Py_NewRef(FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
+ int res = PyList_Append(state->record_list, name);
+ Py_DECREF(name);
if (res < 0) {
return NULL;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]