Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 720acbf

Browse files
committed
Issue python#27981: Fix refleak in fp_setreadl()
Patch by David Dudson.
1 parent 7927e75 commit 720acbf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Parser/tokenizer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ fp_readl(char *s, int size, struct tok_state *tok)
497497
static int
498498
fp_setreadl(struct tok_state *tok, const char* enc)
499499
{
500-
PyObject *readline = NULL, *stream = NULL, *io = NULL;
500+
PyObject *readline = NULL, *stream = NULL, *io = NULL, *bufobj;
501501
_Py_IDENTIFIER(open);
502502
_Py_IDENTIFIER(readline);
503503
int fd;
@@ -528,9 +528,12 @@ fp_setreadl(struct tok_state *tok, const char* enc)
528528
readline = _PyObject_GetAttrId(stream, &PyId_readline);
529529
Py_XSETREF(tok->decoding_readline, readline);
530530
if (pos > 0) {
531-
if (PyObject_CallObject(readline, NULL) == NULL) {
531+
bufobj = PyObject_CallObject(readline, NULL);
532+
if (bufobj == NULL) {
532533
readline = NULL;
533534
goto cleanup;
535+
} else {
536+
Py_DECREF(bufobj);
534537
}
535538
}
536539

0 commit comments

Comments
 (0)