@@ -232,6 +232,8 @@ framelocalsproxy_merge(PyObject* self, PyObject* other)
232
232
Py_DECREF (value );
233
233
}
234
234
235
+ Py_DECREF (iter );
236
+
235
237
return 0 ;
236
238
}
237
239
@@ -242,11 +244,18 @@ framelocalsproxy_keys(PyObject *self, PyObject *__unused)
242
244
PyFrameObject * frame = ((PyFrameLocalsProxyObject * )self )-> frame ;
243
245
PyCodeObject * co = _PyFrame_GetCode (frame -> f_frame );
244
246
247
+ if (names == NULL ) {
248
+ return NULL ;
249
+ }
250
+
245
251
for (int i = 0 ; i < co -> co_nlocalsplus ; i ++ ) {
246
252
PyObject * val = framelocalsproxy_getval (frame -> f_frame , co , i );
247
253
if (val ) {
248
254
PyObject * name = PyTuple_GET_ITEM (co -> co_localsplusnames , i );
249
- PyList_Append (names , name );
255
+ if (PyList_Append (names , name ) < 0 ) {
256
+ Py_DECREF (names );
257
+ return NULL ;
258
+ }
250
259
}
251
260
}
252
261
@@ -258,7 +267,10 @@ framelocalsproxy_keys(PyObject *self, PyObject *__unused)
258
267
if (frame -> f_extra_locals ) {
259
268
assert (PyDict_Check (frame -> f_extra_locals ));
260
269
while (PyDict_Next (frame -> f_extra_locals , & i , & key , & value )) {
261
- PyList_Append (names , key );
270
+ if (PyList_Append (names , key ) < 0 ) {
271
+ Py_DECREF (names );
272
+ return NULL ;
273
+ }
262
274
}
263
275
}
264
276
@@ -306,7 +318,15 @@ framelocalsproxy_visit(PyObject *self, visitproc visit, void *arg)
306
318
static PyObject *
307
319
framelocalsproxy_iter (PyObject * self )
308
320
{
309
- return PyObject_GetIter (framelocalsproxy_keys (self , NULL ));
321
+ PyObject * keys = framelocalsproxy_keys (self , NULL );
322
+ if (keys == NULL ) {
323
+ return NULL ;
324
+ }
325
+
326
+ PyObject * iter = PyObject_GetIter (keys );
327
+ Py_XDECREF (keys );
328
+
329
+ return iter ;
310
330
}
311
331
312
332
static PyObject *
@@ -567,6 +587,11 @@ static PyObject*
567
587
framelocalsproxy_reversed (PyObject * self , PyObject * __unused )
568
588
{
569
589
PyObject * result = framelocalsproxy_keys (self , NULL );
590
+
591
+ if (result == NULL ) {
592
+ return NULL ;
593
+ }
594
+
570
595
if (PyList_Reverse (result ) < 0 ) {
571
596
Py_DECREF (result );
572
597
return NULL ;
0 commit comments