diff --git a/Objects/setobject.c b/Objects/setobject.c --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -440,7 +440,7 @@ { setentry *entry, *table; int table_is_malloced; - Py_ssize_t fill; + Py_ssize_t fill, used; setentry small_copy[PySet_MINSIZE]; #ifdef Py_DEBUG @@ -460,6 +460,7 @@ * clearing. */ fill = so->fill; + used = so->used; if (table_is_malloced) set_empty_to_minsize(so); @@ -478,15 +479,14 @@ * assert that the refcount on table is 1 now, i.e. that this function * has unique access to it, so decref side-effects can't alter it. */ - for (entry = table; fill > 0; ++entry) { + for (entry = table; used > 0; ++entry) { #ifdef Py_DEBUG assert(i < n); ++i; #endif - if (entry->key) { - --fill; - if (entry->key != dummy) - Py_DECREF(entry->key); + if (entry->key && entry->key != dummy) { + used--; + Py_DECREF(entry->key); } #ifdef Py_DEBUG else