Skip to content
Prev Previous commit
Next Next commit
Add INCREF/DECREF for save_set
  • Loading branch information
sweeneyde committed Jun 10, 2022
commit e48b31dbf4647cf15c1e439fb036590d9e69741a
5 changes: 4 additions & 1 deletion Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3431,7 +3431,10 @@ save_set(PicklerObject *self, PyObject *obj)
if (_Pickler_Write(self, &mark_op, 1) < 0)
return -1;
while (_PySet_NextEntry(obj, &ppos, &item, &hash)) {
if (save(self, item, 0) < 0)
Py_INCREF(item);
int err = save(self, item, 0);
Py_CLEAR(item);
if (err < 0)
return -1;
if (++i == BATCHSIZE)
break;
Expand Down