From 6ce7d1ed55b579c03334d8ef7a69102484d02ff1 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 26 Feb 2007 13:48:28 +0000 Subject: [PATCH] Fix a refleak in PyString_Format. --- Objects/stringobject.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Objects/stringobject.c b/Objects/stringobject.c index d772e74c07e..7212df904eb 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -4780,10 +4780,13 @@ PyString_Format(PyObject *format, PyObject *args) reslen += rescnt; if (reslen < 0) { Py_DECREF(result); + Py_XDECREF(temp); return PyErr_NoMemory(); } - if (_PyString_Resize(&result, reslen) < 0) + if (_PyString_Resize(&result, reslen) < 0) { + Py_XDECREF(temp); return NULL; + } res = PyString_AS_STRING(result) + reslen - rescnt; } @@ -4834,6 +4837,7 @@ PyString_Format(PyObject *format, PyObject *args) if (dict && (argidx < arglen) && c != '%') { PyErr_SetString(PyExc_TypeError, "not all arguments converted during string formatting"); + Py_XDECREF(temp); goto error; } Py_XDECREF(temp);