mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
slot_nb_nonzero(): Another leak uncovered by the sandbox datetime
tests. I found the logic too confusing to follow here, so rewrote more than was likely absolutely necessary. Bugfix candidate.
This commit is contained in:
parent
27cae1f7c5
commit
ea7f75d423
1 changed files with 28 additions and 29 deletions
|
@ -3734,30 +3734,29 @@ SLOT0(slot_nb_absolute, "__abs__")
|
||||||
static int
|
static int
|
||||||
slot_nb_nonzero(PyObject *self)
|
slot_nb_nonzero(PyObject *self)
|
||||||
{
|
{
|
||||||
PyObject *func, *res, *args;
|
PyObject *func, *args;
|
||||||
static PyObject *nonzero_str, *len_str;
|
static PyObject *nonzero_str, *len_str;
|
||||||
|
int result = -1;
|
||||||
|
|
||||||
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
|
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
|
||||||
if (func == NULL) {
|
if (func == NULL) {
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return -1;
|
return -1;
|
||||||
func = lookup_maybe(self, "__len__", &len_str);
|
func = lookup_maybe(self, "__len__", &len_str);
|
||||||
if (func == NULL) {
|
if (func == NULL)
|
||||||
if (PyErr_Occurred())
|
return PyErr_Occurred() ? -1 : 1;
|
||||||
return -1;
|
}
|
||||||
else
|
args = PyTuple_New(0);
|
||||||
return 1;
|
if (args != NULL) {
|
||||||
|
PyObject *temp = PyObject_Call(func, args, NULL);
|
||||||
|
Py_DECREF(args);
|
||||||
|
if (temp != NULL) {
|
||||||
|
result = PyObject_IsTrue(temp);
|
||||||
|
Py_DECREF(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args = res = PyTuple_New(0);
|
|
||||||
if (args != NULL) {
|
|
||||||
res = PyObject_Call(func, args, NULL);
|
|
||||||
Py_DECREF(args);
|
|
||||||
}
|
|
||||||
Py_DECREF(func);
|
Py_DECREF(func);
|
||||||
if (res == NULL)
|
return result;
|
||||||
return -1;
|
|
||||||
return PyObject_IsTrue(res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SLOT0(slot_nb_invert, "__invert__")
|
SLOT0(slot_nb_invert, "__invert__")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue