mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
SF patch #1020188: Use Py_CLEAR where necessary to avoid crashes
(Contributed by Dima Dorfman)
This commit is contained in:
parent
410eb84a5d
commit
75ccea3777
5 changed files with 8 additions and 17 deletions
|
|
@ -230,10 +230,7 @@ reversed_next(reversedobject *ro)
|
|||
PyErr_Clear();
|
||||
}
|
||||
ro->index = -1;
|
||||
if (ro->seq != NULL) {
|
||||
Py_DECREF(ro->seq);
|
||||
ro->seq = NULL;
|
||||
}
|
||||
Py_CLEAR(ro->seq);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,7 @@ gen_iternext(PyGenObject *gen)
|
|||
* may keep a chain of frames alive or it could create a reference
|
||||
* cycle. */
|
||||
assert(f->f_back != NULL);
|
||||
Py_DECREF(f->f_back);
|
||||
f->f_back = NULL;
|
||||
Py_CLEAR(f->f_back);
|
||||
|
||||
/* If the generator just returned (as opposed to yielding), signal
|
||||
* that the generator is exhausted. */
|
||||
|
|
|
|||
|
|
@ -192,18 +192,14 @@ calliter_iternext(calliterobject *it)
|
|||
return result; /* Common case, fast path */
|
||||
Py_DECREF(result);
|
||||
if (ok > 0) {
|
||||
Py_DECREF(it->it_callable);
|
||||
it->it_callable = NULL;
|
||||
Py_DECREF(it->it_sentinel);
|
||||
it->it_sentinel = NULL;
|
||||
Py_CLEAR(it->it_callable);
|
||||
Py_CLEAR(it->it_sentinel);
|
||||
}
|
||||
}
|
||||
else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
|
||||
PyErr_Clear();
|
||||
Py_DECREF(it->it_callable);
|
||||
it->it_callable = NULL;
|
||||
Py_DECREF(it->it_sentinel);
|
||||
it->it_sentinel = NULL;
|
||||
Py_CLEAR(it->it_callable);
|
||||
Py_CLEAR(it->it_sentinel);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue