8000 gh-117142: ctypes: Fix memory leak of StgInfo by neonene · Pull Request #118139 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117142: ctypes: Fix memory leak of StgInfo #118139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
use MRO if exists
  • Loading branch information
neonene committed Apr 22, 2024
commit ea1d78c5e69e0028354e234b71e084982fee8196
27 changes: 23 additions & 4 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4883,7 +4883,7 @@ PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
}

static PyTypeObject *
get_base_by_spec(PyTypeObject *type, PyType_Spec *spec)
get_base_by_spec_recursive(PyTypeObject *type, PyType_Spec *spec)
{
PyObject *bases = type->tp_bases;
Py_ssize_t n = PyTuple_GET_SIZE(bases);
Expand All @@ -4895,7 +4895,7 @@ get_base_by_spec(PyTypeObject *type, PyType_Spec *spec)
if (((PyHeapTypeObject*)base)->ht_static_spec == spec) {
return base;
}
base = get_base_by_spec(base, spec);
base = get_base_by_spec_recursive(base, spec);
if (base) {
return base;
}
Expand All @@ -4908,10 +4908,29 @@ _PyType_GetBaseBySpec(PyTypeObject *type, PyType_Spec *spec)
{
assert(spec);
assert(PyType_Check(type));
PyTypeObject *res;
PyTypeObject *res = NULL;

BEGIN_TYPE_LOCK()
res = get_base_by_spec(type, spec);
PyObject *mro = lookup_tp_mro(type);
if (mro == NULL) {
res = get_base_by_spec_recursive(typ 6CFD e, spec);
}
else {
// See PyType_GetModuleByDef() implementation
assert(PyTuple_Check(mro));
assert(PyTuple_GET_SIZE(mro) >= 1);
Py_ssize_t n = PyTuple_GET_SIZE(mro);
for (Py_ssize_t i = 0; i < n; i++) {
PyObject *super = PyTuple_GET_ITEM(mro, i);
if(!_PyType_HasFeature((PyTypeObject *)super, Py_TPFLAGS_HEAPTYPE)) {
continue;
}
if (((PyHeapTypeObject*)super)->ht_static_spec == spec) {
res = _PyType_CAST(super);
break;
}
}
}
END_TYPE_LOCK()

if (res == NULL) {
Expand Down
0