Skip to content

Commit 0387541

Browse files
authored
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.
1 parent 131a3a6 commit 0387541

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎Modules/_testinternalcapi.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,9 @@ record_eval(PyThreadState *tstate, struct _PyInterpreterFrame *f, int exc)
11821182
assert(module != NULL);
11831183
module_state *state = get_module_state(module);
11841184
Py_DECREF(module);
1185-
int res = PyList_Append(state->record_list,
1186-
FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
1185+
PyObject *name = Py_NewRef(FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
1186+
int res = PyList_Append(state->record_list, name);
1187+
Py_DECREF(name);
11871188
if (res < 0) {
11881189
return NULL;
11891190
}
@@ -1244,8 +1245,9 @@ record_eval_interp(PyThreadState *tstate, struct _PyInterpreterFrame *f, int exc
12441245
assert(module != NULL);
12451246
module_state *state = get_module_state(module);
12461247
Py_DECREF(module);
1247-
int res = PyList_Append(state->record_list,
1248-
FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
1248+
PyObject *name = Py_NewRef(FT_ATOMIC_LOAD_PTR_ACQUIRE(func->func_name));
1249+
int res = PyList_Append(state->record_list, name);
1250+
Py_DECREF(name);
12491251
if (res < 0) {
12501252
return NULL;
12511253
}

0 commit comments

Comments
 (0)