diff options
author | Peter Bierma <zintensitydev@gmail.com> | 2024-09-26 10:29:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 10:29:43 (GMT) |
commit | f923605658a29ff9af5a62edc1fc10191977627b (patch) | |
tree | fa26fb24c84fc965468c0f68254451f78fa30314 /Objects | |
parent | 0387c34f7c91428681ca8a4ba4e3d22b9acffde4 (diff) | |
download | cpython-f923605658a29ff9af5a62edc1fc10191977627b.zip cpython-f923605658a29ff9af5a62edc1fc10191977627b.tar.gz cpython-f923605658a29ff9af5a62edc1fc10191977627b.tar.bz2 |
gh-124538: Fix crash when using `gc.get_referents` on an untracked capsule object (#124559)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/capsule.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/capsule.c b/Objects/capsule.c index 555979d..28965e0 100644 --- a/Objects/capsule.c +++ b/Objects/capsule.c @@ -317,10 +317,14 @@ static int capsule_traverse(PyCapsule *capsule, visitproc visit, void *arg) { // Capsule object is only tracked by the GC - // if _PyCapsule_SetTraverse() is called - assert(capsule->traverse_func != NULL); + // if _PyCapsule_SetTraverse() is called, but + // this can still be manually triggered by gc.get_referents() + + if (capsule->traverse_func != NULL) { + return capsule->traverse_func((PyObject*)capsule, visit, arg); + } - return capsule->traverse_func((PyObject*)capsule, visit, arg); + return 0; } |