summaryrefslogtreecommitdiffstats
path: root/Objects/iterobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/iterobject.c')
-rw-r--r--Objects/iterobject.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/Objects/iterobject.c b/Objects/iterobject.c
index ae09d2c..822f9e2 100644
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -222,7 +222,7 @@ calliter_iternext(calliterobject *it)
}
result = _PyObject_CallNoArgs(it->it_callable);
- if (result != NULL) {
+ if (result != NULL && it->it_sentinel != NULL){
int ok;
ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
@@ -230,7 +230,6 @@ calliter_iternext(calliterobject *it)
return result; /* Common case, fast path */
}
- Py_DECREF(result);
if (ok > 0) {
Py_CLEAR(it->it_callable);
Py_CLEAR(it->it_sentinel);
@@ -241,6 +240,7 @@ calliter_iternext(calliterobject *it)
Py_CLEAR(it->it_callable);
Py_CLEAR(it->it_sentinel);
}
+ Py_XDECREF(result);
return NULL;
}