summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>2020-10-12 14:29:01 -0700
committerGitHub <noreply@github.com>2020-10-12 14:29:01 -0700
commit8a12503b4532e33d590ecea7eb94cd0e6b0f1488 (patch)
treeedd0663323a16d3fc114a1eb434b41d1cc152080 /Objects
parent85d59644d9c53dcf4654f0177e2243b86d2a26c9 (diff)
downloadcpython-git-8a12503b4532e33d590ecea7eb94cd0e6b0f1488.tar.gz
bpo-42015: Reorder dereferencing calls in meth_dealloc, to make sure m_self is kept alive long enough (GH-22670)
(cherry picked from commit 04b8631d84a870dda456ef86039c1baf34d08500) Co-authored-by: Yannick Jadoul <yannick.jadoul@belgacom.net>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/methodobject.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c
index 5659f2143d..7b430416c5 100644
--- a/Objects/methodobject.c
+++ b/Objects/methodobject.c
@@ -164,9 +164,11 @@ meth_dealloc(PyCFunctionObject *m)
if (m->m_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject*) m);
}
+ // Dereference class before m_self: PyCFunction_GET_CLASS accesses
+ // PyMethodDef m_ml, which could be kept alive by m_self
+ Py_XDECREF(PyCFunction_GET_CLASS(m));
Py_XDECREF(m->m_self);
Py_XDECREF(m->m_module);
- Py_XDECREF(PyCFunction_GET_CLASS(m));
PyObject_GC_Del(m);
}
@@ -243,9 +245,9 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure)
static int
meth_traverse(PyCFunctionObject *m, visitproc visit, void *arg)
{
+ Py_VISIT(PyCFunction_GET_CLASS(m));
Py_VISIT(m->m_self);
Py_VISIT(m->m_module);
- Py_VISIT(PyCFunction_GET_CLASS(m));
return 0;
}