[Python-checkins] GH-106008: Fix refleak when peepholing `None` comparisons (#106367)

pablogsal webhook-mailer at python.org
Tue Jul 4 06:04:01 EDT 2023


https://github.com/python/cpython/commit/e4ba71fe4b32ae0d7fb3319d697616470fba1e58
commit: e4ba71fe4b32ae0d7fb3319d697616470fba1e58
branch: main
author: Brandt Bucher <brandtbucher at microsoft.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2023-07-04T11:03:57+01:00
summary:

GH-106008: Fix refleak when peepholing `None` comparisons (#106367)

files:
A Misc/NEWS.d/next/Core and Builtins/2023-07-03-11-38-43.gh-issue-106008.HDf1zd.rst
M Python/flowgraph.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-03-11-38-43.gh-issue-106008.HDf1zd.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-03-11-38-43.gh-issue-106008.HDf1zd.rst
new file mode 100644
index 0000000000000..a57b892fd5324
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-03-11-38-43.gh-issue-106008.HDf1zd.rst	
@@ -0,0 +1,2 @@
+Fix possible reference leaks when failing to optimize comparisons with
+:const:`None` in the bytecode compiler.
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 213c993bb863a..e159a4356dfe4 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -1377,9 +1377,9 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
                             goto error;
                         }
                         if (!Py_IsNone(cnt)) {
+                            Py_DECREF(cnt);
                             break;
                         }
-                        Py_DECREF(cnt);
                         if (bb->b_iused <= i + 2) {
                             break;
                         }



More information about the Python-checkins mailing list