diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index d0d1f1f1bc8e53..e3de9006d5a427 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1919,7 +1919,7 @@ pending_identify(PyObject *self, PyObject *args)
PyThread_type_lock mutex = PyThread_allocate_lock();
if (mutex == NULL) {
- return NULL;
+ return PyErr_NoMemory();
}
PyThread_acquire_lock(mutex, WAIT_LOCK);
/* It gets released in _pending_identify_callback(). */