From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Sat, 8 Jun 2024 11:10:44 +0000 (+0200) Subject: [3.12] gh-120244: Fix re.sub() reference leak (GH-120245) (GH-120265) X-Git-Tag: v3.12.5~245 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=46e69f8c2568ce7cc6041f8a601478e39d01efb1;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-120244: Fix re.sub() reference leak (GH-120245) (GH-120265) (cherry picked from commit 38a25e9560cf0ff0b80d9e90bce793ff24c6e027) Co-authored-by: neonene <53406459+neonene@users.noreply.github.com> --- 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 000000000000..d21532f22a1d --- /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 0547390454a3..8ef35d0658c7 100644 --- a/Modules/_sre/sre.c +++ b/Modules/_sre/sre.c @@ -1572,6 +1572,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: