Skip to content

Commit d545695

Browse files
committed
Fix macOS test failures: resolve stack popped lifetime access race condition and interp lookup race
1 parent ed62f39 commit d545695

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Python/crossinterp.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ _PyXIData_CleanupRegistry(PyInterpreterState *interp)
5757
_PyXIData_t *curr = head;
5858
while (curr != NULL) {
5959
_PyXIData_t *next = curr->xid_next;
60+
void *data = curr->data;
61+
xid_freefunc free_func = curr->free;
62+
PyObject *obj = curr->obj;
63+
6064
int expected = _PyXIData_STATUS_ACTIVE;
6165
if (_Py_atomic_compare_exchange_int(&curr->status, &expected, _PyXIData_STATUS_CLAIMED_BY_SENDER_TEARDOWN)) {
62-
if (curr->free != NULL) {
63-
curr->free(curr->data);
66+
if (free_func != NULL) {
67+
free_func(data);
6468
}
65-
curr->data = NULL;
66-
Py_CLEAR(curr->obj);
69+
Py_XDECREF(obj);
6770
}
6871
curr = next;
6972
}

Python/pystate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
10331033

10341034
zapthreads(interp);
10351035

1036+
_PyXIData_CleanupRegistry(interp);
1037+
10361038
// XXX These two calls should be done at the end of clear_interpreter(),
10371039
// but currently some objects get decref'ed after that.
10381040
#ifdef Py_REF_DEBUG
@@ -1069,8 +1071,6 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
10691071

10701072
PyConfig_Clear(&interp->config);
10711073

1072-
_PyXIData_CleanupRegistry(interp);
1073-
10741074
free_interpreter(interp);
10751075
}
10761076

0 commit comments

Comments
 (0)