@@ -204,8 +204,8 @@ template_from_strings_interpolations(PyTypeObject *type, PyObject *strings, PyOb
204204 return NULL ;
205205 }
206206
207- ((templateobject * ) template )-> strings = strings ;
208- ((templateobject * ) template )-> interpolations = interpolations ;
207+ ((templateobject * ) template )-> strings = Py_NewRef ( strings ) ;
208+ ((templateobject * ) template )-> interpolations = Py_NewRef ( interpolations ) ;
209209 return template ;
210210}
211211
@@ -337,7 +337,12 @@ template_concat_templates(templateobject *self, templateobject *other)
337337 return NULL ;
338338 }
339339
340- return template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
340+ PyObject * newtemplate = template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
341+
342+ Py_DECREF (newstrings );
343+ Py_DECREF (newinterpolations );
344+
345+ return newtemplate ;
341346}
342347
343348static PyObject *
@@ -354,7 +359,12 @@ template_concat_template_str(templateobject *self, PyObject *other)
354359 return NULL ;
355360 }
356361
357- return template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
362+ PyObject * newtemplate = template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
363+
364+ Py_DECREF (newstrings );
365+ Py_DECREF (newinterpolations );
366+
367+ return newtemplate ;
358368}
359369
360370static PyObject *
@@ -371,7 +381,12 @@ template_concat_str_template(templateobject *self, PyObject *other)
371381 return NULL ;
372382 }
373383
374- return template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
384+ PyObject * newtemplate = template_from_strings_interpolations (Py_TYPE (self ), newstrings , newinterpolations );
385+
386+ Py_DECREF (newstrings );
387+ Py_DECREF (newinterpolations );
388+
389+ return newtemplate ;
375390}
376391
377392PyObject *
0 commit comments