https://github.com/python/cpython/commit/d3c54f37889436ded4520e78e4e59d3f3350aa44
commit: d3c54f37889436ded4520e78e4e59d3f3350aa44
branch: main
author: Yan Yanchii <[email protected]>
committer: Eclips4 <[email protected]>
date: 2025-02-04T10:38:06Z
summary:

gh-126835: Fix reference leak in `Python/flowgrapc.::optimize_if_const_subscr`  
(#129634)

files:
M Python/flowgraph.c

diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 9ca7fadb8d7665..95ab53ce64301c 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -1500,13 +1500,15 @@ optimize_if_const_subscr(basicblock *bb, int n, 
PyObject *consts, PyObject *cons
     if (!find_load_const_pair(bb, n-1, &arg, &idx)) {
         return SUCCESS;
     }
-    PyObject *o, *key;
+    PyObject *o = NULL, *key = NULL;
     if ((o = get_const_value(arg->i_opcode, arg->i_oparg, consts)) == NULL
         || (key = get_const_value(idx->i_opcode, idx->i_oparg, consts)) == 
NULL)
     {
-        return ERROR;
+        goto error;
     }
     PyObject *newconst = PyObject_GetItem(o, key);
+    Py_DECREF(o);
+    Py_DECREF(key);
     if (newconst == NULL) {
         if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt)) {
             return ERROR;
@@ -1520,6 +1522,10 @@ optimize_if_const_subscr(basicblock *bb, int n, PyObject 
*consts, PyObject *cons
     INSTR_SET_OP0(arg, NOP);
     INSTR_SET_OP0(idx, NOP);
     return SUCCESS;
+error:
+    Py_XDECREF(o);
+    Py_XDECREF(key);
+    return ERROR;
 }
 
 #define VISITED (-1)

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to