Skip to content

Commit 08f43c5

Browse files
committed
review comments
1 parent 2859802 commit 08f43c5

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Objects/setobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,12 @@ make_new_set_basetype(PyTypeObject *type, PyObject *iterable)
11751175
}
11761176

11771177
void
1178+
// gh-140232: check whether a frozenset can be untracked from the GC
11781179
_PyFrozenSet_MaybeUntrack(PyObject *op)
11791180
{
1180-
if (op == NULL || !PyFrozenSet_CheckExact(op)) {
1181+
assert(op != NULL);
1182+
// subclasses of a frozenset can generate reference cycles, so do not untrack
1183+
if (!PyFrozenSet_CheckExact(op)) {
11811184
return;
11821185
}
11831186
// if no elements of a frozenset are tracked by the GC, we untrack the object
@@ -2732,7 +2735,9 @@ PyObject *
27322735
PyFrozenSet_New(PyObject *iterable)
27332736
{
27342737
PyObject *result = make_new_set(&PyFrozenSet_Type, iterable);
2735-
_PyFrozenSet_MaybeUntrack(result);
2738+
if (result != 0) {
2739+
_PyFrozenSet_MaybeUntrack(result);
2740+
}
27362741
return result;
27372742
}
27382743

0 commit comments

Comments
 (0)