summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-03-28 06:05:21 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-03-28 06:05:21 (GMT)
commit55dd2b41e0295526e5a91c37231de00af6fd29d8 (patch)
treea12160921d92b078730411631deecc4b513ba50d
parentadbd28f7b80c31918fb241ca2e3bfb92563f8945 (diff)
downloadcpython-55dd2b41e0295526e5a91c37231de00af6fd29d8.zip
cpython-55dd2b41e0295526e5a91c37231de00af6fd29d8.tar.gz
cpython-55dd2b41e0295526e5a91c37231de00af6fd29d8.tar.bz2
Fix the refleak from test_unicode.
Backport 42973 (lots of whitespace changes intermixed): - Reindent a confusingly indented piece of code (no intended code changes there) - Add missing DECREFs of inner-scope 'temp' variable - Add various missing DECREFs by changing 'return NULL' into 'goto onError' - Avoid double DECREF when last _PyUnicode_Resize() fails Coverity found one of the missing DECREFs, but oddly enough not the others.
-rw-r--r--Objects/unicodeobject.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 310cdaf..690f016 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -7013,15 +7013,15 @@ PyObject *PyUnicode_Format(PyObject *format,
/* nothing to do */;
else if (PyString_Check(temp)) {
/* convert to string to Unicode */
- unicode = PyUnicode_Decode(PyString_AS_STRING(temp),
+ unicode = PyUnicode_Decode(PyString_AS_STRING(temp),
PyString_GET_SIZE(temp),
- NULL,
+ NULL,
"strict");
- Py_DECREF(temp);
- temp = unicode;
- if (temp == NULL)
- goto onError;
- }
+ Py_DECREF(temp);
+ temp = unicode;
+ if (temp == NULL)
+ goto onError;
+ }
else {
Py_DECREF(temp);
PyErr_SetString(PyExc_TypeError,
@@ -7117,11 +7117,13 @@ PyObject *PyUnicode_Format(PyObject *format,
reslen += rescnt;
if (reslen < 0) {
Py_XDECREF(temp);
- Py_DECREF(result);
- return PyErr_NoMemory();
+ PyErr_NoMemory();
+ goto onError;
+ }
+ if (_PyUnicode_Resize(&result, reslen) < 0) {
+ Py_XDECREF(temp);
+ goto onError;
}
- if (_PyUnicode_Resize(&result, reslen) < 0)
- return NULL;
res = PyUnicode_AS_UNICODE(result)
+ reslen - rescnt;
}
@@ -7171,6 +7173,7 @@ PyObject *PyUnicode_Format(PyObject *format,
if (dict && (argidx < arglen) && c != '%') {
PyErr_SetString(PyExc_TypeError,
"not all arguments converted during string formatting");
+ Py_XDECREF(temp);
goto onError;
}
Py_XDECREF(temp);
@@ -7182,12 +7185,12 @@ PyObject *PyUnicode_Format(PyObject *format,
goto onError;
}
+ if (_PyUnicode_Resize(&result, reslen - rescnt) < 0)
+ goto onError;
if (args_owned) {
Py_DECREF(args);
}
Py_DECREF(uformat);
- if (_PyUnicode_Resize(&result, reslen - rescnt) < 0)
- goto onError;
return (PyObject *)result;
onError: