Skip to content

Commit c7defe2

Browse files
committed
Remove spurious Py_DECREF on borrowed ref in LOAD_GLOBAL specialization
_PyDict_LookupIndexAndValue() returns a borrowed reference via _Py_dict_lookup(), but specialize_load_global_lock_held() called Py_DECREF(value) on it when bailing out for lazy imports. Each time the adaptive counter fired while a lazy import was still in globals, this stole one reference from the dict's object. With 8+ threads racing through LOAD_GLOBAL during concurrent lazy import resolution, enough triggers accumulated to drive the refcount to zero while the dict and other threads still referenced the object, causing use-after-free.
1 parent 2e3e76e commit c7defe2

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

Python/specialize.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,6 @@ specialize_load_global_lock_held(
13211321
}
13221322
if (value != NULL && PyLazyImport_CheckExact(value)) {
13231323
SPECIALIZATION_FAIL(LOAD_GLOBAL, SPEC_FAIL_ATTR_MODULE_LAZY_VALUE);
1324-
Py_DECREF(value);
13251324
goto fail;
13261325
}
13271326
PyInterpreterState *interp = _PyInterpreterState_GET();

0 commit comments

Comments
 (0)