https://github.com/python/cpython/commit/38a25e9560cf0ff0b80d9e90bce793ff24c6e027
commit: 38a25e9560cf0ff0b80d9e90bce793ff24c6e027
branch: main
author: neonene <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-06-08T10:22:07Z
summary:

gh-120244: Fix re.sub() reference leak (GH-120245)

files:
A Misc/NEWS.d/next/Library/2024-06-08-09-45-31.gh-issue-120244.8o9Dzr.rst
M Modules/_sre/sre.c

diff --git 
a/Misc/NEWS.d/next/Library/2024-06-08-09-45-31.gh-issue-120244.8o9Dzr.rst 
b/Misc/NEWS.d/next/Library/2024-06-08-09-45-31.gh-issue-120244.8o9Dzr.rst
new file mode 100644
index 00000000000000..d21532f22a1d38
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-06-08-09-45-31.gh-issue-120244.8o9Dzr.rst
@@ -0,0 +1 @@
+Fix memory leak in :func:`re.sub()` when the replacement string contains 
backreferences.
diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c
index c1eff63d921de9..e33034086481c2 100644
--- a/Modules/_sre/sre.c
+++ b/Modules/_sre/sre.c
@@ -1622,6 +1622,7 @@ _sre_template_impl(PyObject *module, PyObject *pattern, 
PyObject *template)
         }
         self->items[i].literal = Py_XNewRef(literal);
     }
+    PyObject_GC_Track(self);
     return (PyObject*) self;
 
 bad_template:

_______________________________________________
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