Py_DECREF(value);
}
+ Py_DECREF(iter);
+
return 0;
}
PyFrameObject *frame = ((PyFrameLocalsProxyObject*)self)->frame;
PyCodeObject *co = _PyFrame_GetCode(frame->f_frame);
+ if (names == NULL) {
+ return NULL;
+ }
+
for (int i = 0; i < co->co_nlocalsplus; i++) {
PyObject *val = framelocalsproxy_getval(frame->f_frame, co, i);
if (val) {
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
- PyList_Append(names, name);
+ if (PyList_Append(names, name) < 0) {
+ Py_DECREF(names);
+ return NULL;
+ }
}
}
if (frame->f_extra_locals) {
assert(PyDict_Check(frame->f_extra_locals));
while (PyDict_Next(frame->f_extra_locals, &i, &key, &value)) {
- PyList_Append(names, key);
+ if (PyList_Append(names, key) < 0) {
+ Py_DECREF(names);
+ return NULL;
+ }
}
}
static PyObject *
framelocalsproxy_iter(PyObject *self)
{
- return PyObject_GetIter(framelocalsproxy_keys(self, NULL));
+ PyObject* keys = framelocalsproxy_keys(self, NULL);
+ if (keys == NULL) {
+ return NULL;
+ }
+
+ PyObject* iter = PyObject_GetIter(keys);
+ Py_XDECREF(keys);
+
+ return iter;
}
static PyObject *
framelocalsproxy_reversed(PyObject *self, PyObject *__unused)
{
PyObject *result = framelocalsproxy_keys(self, NULL);
+
+ if (result == NULL) {
+ return NULL;
+ }
+
if (PyList_Reverse(result) < 0) {
Py_DECREF(result);
return NULL;