Skip to content

_threadmodule does not check for NULL after PyType_GetModuleByDef calls #114414

Closed
@sobolevn

Description

@sobolevn

Bug report

PyType_GetModuleByDef can return NULL:

cpython/Objects/typeobject.c

Lines 4640 to 4645 in fd49e22

PyErr_Format(
PyExc_TypeError,
"PyType_GetModuleByDef: No superclass of '%s' has the given module",
type->tp_name);
return NULL;
}

I think that right now this is a hypothetical issue, because in practice NULL will never be returned for these samples. But, all other similar places do check for NULL. I guess that adding a check won't hurt. And in the future, if something changes - we would be safe.

Samples:

PyObject *module = PyType_GetModuleByDef(type, &thread_module);
thread_module_state *state = get_thread_state(module);

PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
thread_module_state *state = get_thread_state(module);

PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
thread_module_state *state = get_thread_state(module);

Linked PRs

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions