Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e35b657

Browse files
committed
Fix cleanup DECREF logic in builtin_filter function.
1 parent 150db73 commit e35b657

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Python/bltinmodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,15 @@ builtin_filter(PyObject *self, PyObject *args)
210210
if (PyTuple_Check(seq))
211211
return filtertuple(func, seq);
212212

213+
/* Pre-allocate argument list tuple. */
214+
arg = PyTuple_New(1);
215+
if (arg == NULL)
216+
return NULL;
217+
213218
/* Get iterator. */
214219
it = PyObject_GetIter(seq);
215220
if (it == NULL)
216-
return NULL;
221+
goto Fail_arg;
217222

218223
/* Guess a result list size. */
219224
len = PyObject_Size(seq);
@@ -222,11 +227,6 @@ builtin_filter(PyObject *self, PyObject *args)
222227
len = 8; /* arbitrary */
223228
}
224229

225-
/* Pre-allocate argument list tuple. */
226-
arg = PyTuple_New(1);
227-
if (arg == NULL)
228-
goto Fail_arg;
229-
230230
/* Get a result list. */
231231
if (PyList_Check(seq) && seq->ob_refcnt == 1) {
232232
/* Eww - can modify the list in-place. */

0 commit comments

Comments
 (0)