Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix reference counting when adjacent literal parts are merged while constructing
:class:`string.templatelib.Template`, preventing the displaced string object
from leaking.
3 changes: 2 additions & 1 deletion Objects/templateobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,14 @@ template_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (last_was_str) {
PyObject *laststring = PyTuple_GET_ITEM(strings, stringsidx - 1);
PyObject *concat = PyUnicode_Concat(laststring, item);
Py_DECREF(laststring);
if (!concat) {
Py_DECREF(strings);
Py_DECREF(interpolations);
return NULL;
}
/* Replace laststring with concat */
PyTuple_SET_ITEM(strings, stringsidx - 1, concat);
Py_DECREF(laststring);
}
else {
PyTuple_SET_ITEM(strings, stringsidx++, Py_NewRef(item));
Expand Down
Loading