From 11fe96b03381052695982e81b58b704f6a4c847e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 19 Oct 2026 13:41:27 -0700 Subject: [PATCH] gh-159739: Initialize template iterator references before allocating Backport to 3.15 and 3.14. --- .../2026-10-19-20-38-17.gh-issue-159739.fc0ed2.rst | 2 ++ Objects/templateobject.c | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-20-38-17.gh-issue-159739.fc0ed2.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-20-38-17.gh-issue-159739.fc0ed2.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-20-38-17.gh-issue-159739.fc0ed2.rst new file mode 100644 index 00000000000000..6a549a6ded5e6a --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-20-38-17.gh-issue-159739.fc0ed2.rst @@ -0,0 +1,2 @@ +Avoid a crash if allocation fails while creating a +:class:`string.templatelib.Template` iterator. diff --git a/Objects/templateobject.c b/Objects/templateobject.c index 1609e82b444516..994b352d7dcd63 100644 --- a/Objects/templateobject.c +++ b/Objects/templateobject.c @@ -226,6 +226,8 @@ template_iter(PyObject *op) if (iter == NULL) { return NULL; } + iter->stringsiter = NULL; + iter->interpolationsiter = NULL; PyObject *stringsiter = PyObject_GetIter(self->strings); if (stringsiter == NULL) {